Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type mismatch error on IF Statement

Status
Not open for further replies.

sshafe

Programmer
Oct 18, 2002
71
US
Let me first say I am new to the vbscript environment. I have worked with 6.0 and .NET before, but I am having problems converting to this style.
I am getting the error Type Mismatch error on an IF statement line... What am I doing wrong? Please help

The code:
SQL_STATEMENT = "SELECT COUNT(*) FROM vbscript_test WHERE user_id = '" & _
strUserName & "' AND group_id = '" & strUserGroup & "';"
Set CheckUser = cnMcLDBA.Execute(SQL_STATEMENT)

If CheckUser = 0 Then ****This line has the error
Set Update = cnMcLDBA.Execute("INSERT INTO vbscript_test VALUES('" & _
strUserName & "','" & strUserGroup & "');")
 
I can't swear to it but the sql statement is probably returning a string. To use it like: If CheckUser = 0 Then

you may have to change it to:

If CheckUser = CInt(0) Then

That way it will see 0 as a number and not a string. Rob
Just my $.02.
 
Just for anyone else who has this problem. I found the solution:

I was reading through a recordset and needing to check that:

Set CheckUser = cnMcLDBA.Execute("SELECT COUNT(*) FROM vbscript_test WHERE user_id = '" & _
strUserName & "' AND group_id = '" & strUserGroup & "';")
CheckUser.moveFirst 'Move the recordset to first position

If CheckUser(0) = 0 Then
Set Update = cnMcLDBA.Execute("INSERT INTO vbscript_test VALUES('" & _
strUserName & "','" & strUserGroup & "');")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top