Unexpected VB Error

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Unexpected VB Error

Post by mightycpa » Mon Jan 12, 2004 7:02 pm

Hi,

This VB code causes two errors:

Function GetTimeEntry(SerNum)
Dim SQLString
Dim AcctNum
Dim SerNum

set MyDB = CreateObject("ADODB.Connection")
MyDB.Open "GATER"

SQLString = "SELECT time.* FROM [time] where time.serial = '" & SerNum & "';"
'MsgBox SQLString

set rsTime = MyDB.Execute(SQLString)

If Not rsTime.EOF then
AcctNum = rsTime.Fields("account")
Else
AcctNum = "Not Found"
End if

MyDB.Close

GetTimeEntry = AcctNum
End Function


but if I take out the DIM statements, I'm oK.

Here are the VBscript runtime errors:

Error 1041, Line 5, Column 5, "name redefined"
Error 13, Line 2, Column 0 "Type mismatch: 'GetTimeEntry'"

Get rid of the dims, and the code runs fine.... why?

Should I care?

Tx,

George
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Jan 13, 2004 7:01 am

Off the top of my head, untested, not used VB in a while.......:

Have you tried?

1.
set SQLString = "Select ........

And/Or

2.
Does SQLString need a semicolon ";" at the end?


I think the second message is because SQLString failed in the first message. I think using "set" will correct the first error, and that fix will eliminate the second error message.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Jan 13, 2004 8:43 am

Hi,

The problem is you have declared SerNum twice. Remove the Dim SerNum statement. It is already declared in the function header. SerNum is the variable which contains the value passed to the function.
MJT Net Support
[email protected]

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Thanks!

Post by mightycpa » Tue Jan 13, 2004 2:53 pm

Your support is great, thanks.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts