Run Time Error 3075

D

Denver

Private Sub cmdLogIn_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.Combo33) Or Me.Combo33 = "" Then
MsgBox "Select a User Name first.", vbOKOnly, "Required Data"
Me.Combo33.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.Text10) Or Me.Text10 = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.Text10.SetFocus
Exit Sub
End If

'Check value of password in tblUser List & Permission to see if this
'matches value chosen in combo box
Permission)", _
"[User Name]=" & Me.Combo33.Value) Then <<< HERE IS
THE ERROR

strUserName = Me.Combo33.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogIn", acSaveNo
DoCmd.OpenForm "frmSplash_Screen"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Text10.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact
admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If

I have a Form for user log in, I have a combobox bound in tbl [User List &
Permission] the above VBA code works will, RUN TIME ERROR 3075 occurs when I
clik my cmdLogIn it says Run Time Error '3075': Syntax error (missing
operator) in query expression '[User Name]=Ricky Davao'.

what do I miss in my codes?

thanks for any help, I appreciate
 
D

Douglas J. Steele

Because you're dealing with text data, you must use quotes around the value:

If Me.Text10.Value = DLookup("Password", "tbl(User List & Permission)", _
"[User Name]=""" & Me.Combo33.Value & """") Then

I used three double quotes in front and four double quotes afterwards, just
in case there are apostrophes in the name.

Note that you can simplify your two If statements using

If Len(Me.Combo33 & vbNullString) = 0 Then


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Denver said:
Private Sub cmdLogIn_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.Combo33) Or Me.Combo33 = "" Then
MsgBox "Select a User Name first.", vbOKOnly, "Required Data"
Me.Combo33.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.Text10) Or Me.Text10 = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.Text10.SetFocus
Exit Sub
End If

'Check value of password in tblUser List & Permission to see if this
'matches value chosen in combo box
Permission)", _
"[User Name]=" & Me.Combo33.Value) Then <<< HERE
IS
THE ERROR

strUserName = Me.Combo33.Value

'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogIn", acSaveNo
DoCmd.OpenForm "frmSplash_Screen"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Text10.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact
admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If

I have a Form for user log in, I have a combobox bound in tbl [User List
&
Permission] the above VBA code works will, RUN TIME ERROR 3075 occurs when
I
clik my cmdLogIn it says Run Time Error '3075': Syntax error (missing
operator) in query expression '[User Name]=Ricky Davao'.

what do I miss in my codes?

thanks for any help, I appreciate
 
N

NG

Hi,

the user name has to be between "", try:

"[User Name]= """ & Me.Combo33.Value) & """"
--
Kind regards
Noëlla


:

........
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top