ACalcutt Posted September 19, 2008 Share Posted September 19, 2008 (edited) Hello eveyone, I am trying to use the attached AccessCom.au3 udf that is attached in my Vistumbler program (www.vistumbler.net). It is based on the work here (http://www.autoitscript.com/forum/index.php?showtopic=32144) Mostly it works well, but I am getting a random error sometimes when i load a data file into the database The error I am getting is this C:\Users\ACalcutt\Documents\Vistumbler\VistumblerMDB\AccessCom.au3 (373) : ==> Nested "With" statements are not allowed.: With $o_adoRs ^ ERROR What is a "nested with" and how do i fix this error. Does anyone have any idea how i can fix this? The function that it is getting this error from is this one Func _RecordSearch($s_dbname, $_query, ByRef $o_adoCon, $i_adoMDB = 1, $USRName = "", $PWD = "") If Not IsObj($o_adoCon) Then _AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD) $i_NeedToCloseInFunc = 1 Else $i_NeedToCloseInFunc = 0 EndIf $o_adoRs = ObjCreate("ADODB.Recordset") $o_adoRs.CursorType = 1 $o_adoRs.LockType = 3 $o_adoRs.Open($_query, $o_adoCon) With $o_adoRs Dim $_output[.RecordCount + 1][.Fields.Count + 1] $_output[0][0] = .RecordCount For $i = 1 To .Fields.Count $_output[0][$i] = .Fields($i - 1).Name Next If $o_adoRs.RecordCount Then $z = 0 While Not .EOF $z = $z + 1 For $x = 1 To .Fields.Count $_output[$z][$x] = .Fields($x - 1).Value Next .MoveNext WEnd EndIf EndWith $o_adoRs.Close If $i_NeedToCloseInFunc Then $o_adoCon.Close Return $_output EndFunc ;==>_RecordSearch The latest version of vistumbler that uses this UDF is here (http://forum.techidiots.net/forum/viewtopic.php?f=26&t=126) Example data can be found here...though this is a big list of data (http://forum.techidiots.net/forum/viewtopic.php?f=16&t=131)AccessCom.au3 Edited September 19, 2008 by ACalcutt Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature Link to comment Share on other sites More sharing options...
LarryDalooza Posted September 19, 2008 Share Posted September 19, 2008 I am guessing that within a With/EndWith you are calling a function that itself has a With/EndWith With FuncCall() EndWith Func FuncCall With EndWith EndFunc Perhaps that is throwing the nested With. I am sure nested Withs are possible... just not implemented. So With/EndWith should be used minimally just too cut down on redundancy. Lar. AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
ACalcutt Posted September 19, 2008 Author Share Posted September 19, 2008 As far as i can tell there are no With's inside With's... I don't use any with in my program, and this function is called directly. The also arn't any other AccessCom functions that call _RecordSearch as far as i can see Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature Link to comment Share on other sites More sharing options...
ACalcutt Posted September 20, 2008 Author Share Posted September 20, 2008 anybody have any other suggestions? Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature Link to comment Share on other sites More sharing options...
trancexx Posted September 20, 2008 Share Posted September 20, 2008 anybody have any other suggestions?Maybe there are Withs inside With but we don't see them. Try this code to see that there are Withs out there... $obj = ObjCreate("Shell.Application") $obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc").ParseName(""), 0) Error is intentional You should get "blah, blah... Object referenced outside a "With" statement..." ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
ACalcutt Posted September 23, 2008 Author Share Posted September 23, 2008 (edited) Maybe there are Withs inside With but we don't see them. Try this code to see that there are Withs out there... $obj = ObjCreate("Shell.Application") $obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc").ParseName(""), 0) Error is intentional You should get "blah, blah... Object referenced outside a "With" statement..." I made a copy of _RecordSearch() and called it _RecordSearch2()...right above the "with" that keeps having problems I put that code. i replaced each _RecordSearch() reference to _RecordSearch2() in my import function one at a time. every time it came up as the error it should have >Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Users\Andrew\Desktop\VistumblerMDB\Vistumbler.au3" C:\Users\Andrew\Desktop\VistumblerMDB\AccessCom.au3 (408) : ==> Object referenced outside a "With" statement.: $obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc" ).ParseName(""), 0) $obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc" )^ ERROR Edited September 23, 2008 by ACalcutt Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature Link to comment Share on other sites More sharing options...
trancexx Posted September 24, 2008 Share Posted September 24, 2008 (edited) I made a copy of _RecordSearch() and called it _RecordSearch2()...right above the "with" that keeps having problems I put that code. i replaced each _RecordSearch() reference to _RecordSearch2() in my import function one at a time. every time it came up as the error it should haveI don't get your point. What is your point? That little code was supposed to be an example of "With" showing up as (in) error without using "With... EndWith" in our code. It has nothing to do with AccessCom.au3 As for your original problem... Try removing "With... EndWith" knowing that (for example): With $o_adoRs $r_count = .RecordCount $f_count = .Fields.Count EndWith is the same as: $r_count = $o_adoRs.RecordCount $f_count = $o_adoRs.Fields.Count Maybe it helps and than again... Edited September 24, 2008 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
ACalcutt Posted September 27, 2008 Author Share Posted September 27, 2008 Hmmm maybe i misunderstood what that code was supposed to do. From what i gather it tells you if that code in inside a with. I put it into AccessCom.au3 because that is where I am getting the nested with error. I put it right before the line the gets the nested with error (in AccessCom.au3) and every time it was called it said it was not inside a with. I will try out your other suggestion Thanks Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature Link to comment Share on other sites More sharing options...
ACalcutt Posted September 27, 2008 Author Share Posted September 27, 2008 (edited) Ok... I replaced this Func _RecordSearch($s_dbname, $_query, ByRef $o_adoCon, $i_adoMDB = 1, $USRName = "", $PWD = "") If Not IsObj($o_adoCon) Then _AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD) $i_NeedToCloseInFunc = 1 Else $i_NeedToCloseInFunc = 0 EndIf $o_adoRs = ObjCreate("ADODB.Recordset") $o_adoRs.CursorType = 1 $o_adoRs.LockType = 3 $o_adoRs.Open($_query, $o_adoCon) With $o_adoRs Dim $_output[.RecordCount + 1][.Fields.Count + 1] $_output[0][0] = .RecordCount For $i = 1 To .Fields.Count $_output[0][$i] = .Fields($i - 1).Name Next If $o_adoRs.RecordCount Then $z = 0 While Not .EOF $z = $z + 1 For $x = 1 To .Fields.Count $_output[$z][$x] = .Fields($x - 1).Value Next .MoveNext WEnd EndIf EndWith $o_adoRs.Close If $i_NeedToCloseInFunc Then $o_adoCon.Close Return $_output EndFunc ;==>_RecordSearch With This Func _RecordSearch($s_dbname, $_query, ByRef $o_adoCon, $i_adoMDB = 1, $USRName = "", $PWD = "") If Not IsObj($o_adoCon) Then _AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD) $i_NeedToCloseInFunc = 1 Else $i_NeedToCloseInFunc = 0 EndIf $o_adoRs = ObjCreate("ADODB.Recordset") $o_adoRs.CursorType = 1 $o_adoRs.LockType = 3 $o_adoRs.Open($_query, $o_adoCon) $r_count = $o_adoRs.RecordCount $f_count = $o_adoRs.Fields.Count Dim $_output[$r_count + 1][$f_count + 1] $_output[0][0] = $r_count For $i = 1 To $f_count $_output[0][$i] = $o_adoRs.Fields($i - 1).Name Next If $r_count Then $z = 0 While Not $o_adoRs.EOF $z = $z + 1 For $x = 1 To $f_count $_output[$z][$x] = $o_adoRs.Fields($x - 1).Value Next $o_adoRs.MoveNext WEnd EndIf $o_adoRs.Close If $i_NeedToCloseInFunc Then $o_adoCon.Close Return $_output EndFunc ;==>_RecordSearch It's still importing, so it looks like i did it right... I'll see if i still get random errors with this (it should no longer get a nested with error at least...since there is no with) Edited September 27, 2008 by ACalcutt Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature Link to comment Share on other sites More sharing options...
ACalcutt Posted September 30, 2008 Author Share Posted September 30, 2008 (edited) Thanks, This seems to have fixed my problemAccessCom.au3 Edited September 30, 2008 by ACalcutt Andrew Calcutt Http://www.Vistumbler.net Http://www.TechIdiots.net Its not an error, its a undocumented feature Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now