Need help in debug compile error please

Alvin85

Registered User.
Local time
Tomorrow, 01:08
Joined
Jul 7, 2018
Messages
17
Hi,
I am trying to insert a new row of data into the table UserTable if the UserLogin is not found in the table. When i run the coding, an error appear. Compile error: Expected Expression. May i ask how do i solve this problem?

Following is my coding:

If isnull ( select [UserLogin] from UserTable where [UserLogin] like me.txtLogin.value ) then

CurrentDb.execute "insert into UserTable (Username, UserLogin, UserPass) values ( '" & me.txtName.value & "', '" & me.txtLogin.value & '",'" & me.txtPass.value & "')

Else
Magnox "User is already in Table"

End if
 
Probably I would do this:

Instead of:
Code:
If isnull ( select [UserLogin] from UserTable where [UserLogin] like me.txtLogin.value ) then

I might use
Code:
If DCount("[UserLogin]", "UserTable", "[UserLogin]='" & Me.TxtLogin & '") = 0 Then

Your "If IsNull..." statement is mixing VBA and SQL in a way that is not legal. Your CurrentDB.Execute correctly segregates the VBA (not in quotes) from the SQL (in quotes) and provides a method (.Execute) for the SQL to be executed. However, no such mechanism of execution is present in the "If IsNull..." line.
 

Users who are viewing this thread

Back
Top Bottom