Can't reference property error...

  • Thread starter Thread starter BobRoyAce
  • Start date Start date
B

BobRoyAce

I have two text boxes on a form where a user can enter a Username and
Password. Once they click on a button, I want to do a query against a Users
table to see if the login exists. I construct the SQL as follows:

Dim sSQL as string

sSQL = "SELECT UserID FROM Users " & _
"WHERE (UserName = """ & Trim$(txtUsername.Text) & """)" & _
"AND (UserPassword = """ & Trim$(txtPassword.Text) & """)"

When the line assigning to sSQL is run, I get an error message that states:

"You can't reference a property or method for a control unless the control
has the focus."

Why does this not work and how do I get around it?
 
Did you try to omit ".Text" from your statement? As far as I recall,
Text is the value of a text box while it has focus and its value has
changed, while the old value is kept in Value. Once a textbox loses
focus, Text becomes Value. I may be wrong but its easy to try replacing
txtUsername.Text with Me.txtUsername.
I can't quite see what kind of quotes you put in there but you want
single quotes encased in double quotes : "'", not """:

"WHERE (UserName LIKE "'*" & Me.txtUsername & "*')"

Good luck,
Pavel
 
Back
Top