Syntax error

G

Guest

Hey all,
I've been working with this code for a while, and I'm hoping to get some
help with a problem I'm running into at the end.

I have a login form that is being set up so users must login with a username
and password before they can access the main form in the database. Only
problem is, when users enter their info and hit enter...nothing happens. When
I debugged step by step, it told me I had a syntax error, so I'm guessing
that may be the problem?

<B>Here's all the code:</B>



Private Sub cmdLogin_Click()

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

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

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

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

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
Dim strFilter As String
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then
<B>'When I reach the above If line in debug mode, it tells me "Run time
error 3075,"syntax error in string in query expression '[EmployeeID]=
5079".</B>


'Close logon form and open splash screen
DoCmd.OpenForm "NewDailyReport"
DoCmd.Close acForm, "StartForm", acSaveNo

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.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

End Sub


Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub


<B>Thanks so much!</B>
 
J

John Welch

Evan- it looks like your problem is in this line:
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
The problem is with with quotes- you have a single quote after the value,
but not before it. Assuming your EmployeeId is a numeric value, I would just
say this:

strFilter = "[EmployeeID]= " & Me.cboEmployee

hope this helps
-John
 
R

Rob Oldfield

EmployeeID is text? If not, lose the 's round it (though I've just noticed
that you seem to have a closing ', but no opening ')

Couple of other points... you shouldn't need the .value and you should take
a look at the nz function. And this type of security gives you no security
at all.
 
G

Guest

Hey guys,
Thanks so much for the help! However, I've only come halfway. Now, the
button does have an action, it takes me to the form I wanted it to, but it
doesn't filter the results based on the employee ID number. My goal is for an
employee to type in their number, and only view the previous records that
have that employee ID number already (and be able to create a new one). As of
now, the cmd button opens the new form, but all records are visible. I've
tried both:

Dim strFilter As String
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee)
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then

Dim strFilter As String
strFilter = "[EmployeeID]= " & Me.cboEmployee
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then


Anyone have any ideas? I'm so close, so I'll be eagerly awaiting your
responses. Thanks again.
- Evan


John Welch said:
Evan- it looks like your problem is in this line:
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
The problem is with with quotes- you have a single quote after the value,
but not before it. Assuming your EmployeeId is a numeric value, I would just
say this:

strFilter = "[EmployeeID]= " & Me.cboEmployee

hope this helps
-John

Evan Goldin said:
Hey all,
I've been working with this code for a while, and I'm hoping to get some
help with a problem I'm running into at the end.

I have a login form that is being set up so users must login with a
username
and password before they can access the main form in the database. Only
problem is, when users enter their info and hit enter...nothing happens.
When
I debugged step by step, it told me I had a syntax error, so I'm guessing
that may be the problem?

<B>Here's all the code:</B>



Private Sub cmdLogin_Click()

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

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

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

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

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
Dim strFilter As String
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then
<B>'When I reach the above If line in debug mode, it tells me "Run time
error 3075,"syntax error in string in query expression '[EmployeeID]=
5079".</B>


'Close logon form and open splash screen
DoCmd.OpenForm "NewDailyReport"
DoCmd.Close acForm, "StartForm", acSaveNo

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.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

End Sub


Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub


<B>Thanks so much!</B>
 
T

TC

You've only shown us two 'IF' tests. You need to also show the code
that comes within those tests. It's a bit like me saying: "The answer
to your question is ... arghhh!! (silence)"

HTH,
TC
 
J

John Welch

If you want your form to be filtered when it opens, you have to tell it so.
Your problem now isn't then if... then, it's what you say after the then:

'Close logon form and open splash screen
this will just open the form with no filter. To filter it based on your
employeeID, you have to give it a "where condition" (look this up in help
under docmd.openform).

so you would say:
DoCmd.OpenForm "NewDailyReport",,,"[employeeID]=" & me.cboEmployee

-John



Evan Goldin said:
Hey guys,
Thanks so much for the help! However, I've only come halfway. Now, the
button does have an action, it takes me to the form I wanted it to, but it
doesn't filter the results based on the employee ID number. My goal is for
an
employee to type in their number, and only view the previous records that
have that employee ID number already (and be able to create a new one). As
of
now, the cmd button opens the new form, but all records are visible. I've
tried both:

Dim strFilter As String
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee)
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then

Dim strFilter As String
strFilter = "[EmployeeID]= " & Me.cboEmployee
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then


Anyone have any ideas? I'm so close, so I'll be eagerly awaiting your
responses. Thanks again.
- Evan


John Welch said:
Evan- it looks like your problem is in this line:
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
The problem is with with quotes- you have a single quote after the value,
but not before it. Assuming your EmployeeId is a numeric value, I would
just
say this:

strFilter = "[EmployeeID]= " & Me.cboEmployee

hope this helps
-John

Evan Goldin said:
Hey all,
I've been working with this code for a while, and I'm hoping to get
some
help with a problem I'm running into at the end.

I have a login form that is being set up so users must login with a
username
and password before they can access the main form in the database. Only
problem is, when users enter their info and hit enter...nothing
happens.
When
I debugged step by step, it told me I had a syntax error, so I'm
guessing
that may be the problem?

<B>Here's all the code:</B>



Private Sub cmdLogin_Click()

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

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

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

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

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
Dim strFilter As String
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then
<B>'When I reach the above If line in debug mode, it tells me "Run time
error 3075,"syntax error in string in query expression '[EmployeeID]=
5079".</B>


'Close logon form and open splash screen
DoCmd.OpenForm "NewDailyReport"
DoCmd.Close acForm, "StartForm", acSaveNo

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.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

End Sub


Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub


<B>Thanks so much!</B>
 
G

Guest

Hey John,
I'm still running into problems with that code. With that code, an "Enter
Parameter" pop-up box comes up after clicking the button, and it asks me to
enter the employeeID number. If I enter the employeeID number that I have
already entered on the login form, it takes me to the correct form (and it
seems as though the filter is on), but it isn't filtering the results, it's
still showing all forms, no matter the employeeID number. However, if I enter
a completely random, wrong number on the pop-up box, then it takes me to the
filtered form with NO old records. How should I proceed? Is there something
I'm missing?
- Evan

I used
DoCmd.OpenForm "NewDailyReport",,,"[employeeID]=" & me.cboEmployee
where you instructed me to.


John Welch said:
If you want your form to be filtered when it opens, you have to tell it so.
Your problem now isn't then if... then, it's what you say after the then:

'Close logon form and open splash screen
this will just open the form with no filter. To filter it based on your
employeeID, you have to give it a "where condition" (look this up in help
under docmd.openform).

so you would say:
DoCmd.OpenForm "NewDailyReport",,,"[employeeID]=" & me.cboEmployee

-John



Evan Goldin said:
Hey guys,
Thanks so much for the help! However, I've only come halfway. Now, the
button does have an action, it takes me to the form I wanted it to, but it
doesn't filter the results based on the employee ID number. My goal is for
an
employee to type in their number, and only view the previous records that
have that employee ID number already (and be able to create a new one). As
of
now, the cmd button opens the new form, but all records are visible. I've
tried both:

Dim strFilter As String
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee)
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then

Dim strFilter As String
strFilter = "[EmployeeID]= " & Me.cboEmployee
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then


Anyone have any ideas? I'm so close, so I'll be eagerly awaiting your
responses. Thanks again.
- Evan


John Welch said:
Evan- it looks like your problem is in this line:
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
The problem is with with quotes- you have a single quote after the value,
but not before it. Assuming your EmployeeId is a numeric value, I would
just
say this:

strFilter = "[EmployeeID]= " & Me.cboEmployee

hope this helps
-John

Hey all,
I've been working with this code for a while, and I'm hoping to get
some
help with a problem I'm running into at the end.

I have a login form that is being set up so users must login with a
username
and password before they can access the main form in the database. Only
problem is, when users enter their info and hit enter...nothing
happens.
When
I debugged step by step, it told me I had a syntax error, so I'm
guessing
that may be the problem?

<B>Here's all the code:</B>



Private Sub cmdLogin_Click()

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

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

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

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

'Check value of password in tblEmployees to see if this
'matches value chosen in combo box
Dim strFilter As String
strFilter = "[EmployeeID]= " & Str(Me.cboEmployee.Value) & "'"
If Me.txtPassword.Value = DLookup("strEmpPassword", "tblemployees",
strFilter) Then
<B>'When I reach the above If line in debug mode, it tells me "Run time
error 3075,"syntax error in string in query expression '[EmployeeID]=
5079".</B>


'Close logon form and open splash screen
DoCmd.OpenForm "NewDailyReport"
DoCmd.Close acForm, "StartForm", acSaveNo

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.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

End Sub


Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub


<B>Thanks so much!</B>
 

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