Syntax error message (missing operator)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have searched posts for error message problems and can't seem to find a
solution to my problem.

I have an unbound form that has combo boxes for form and report selections.
I have an unbound text box to enter job number to. I use the following code:

Private Sub ComboFormList_Click()
On Error GoTo Err_ComboFormList_Click

Dim stFormName As String

stFormName = Me.ComboFormList

If IsNull(JobNumber) Then
MsgBox ("Please enter job number before making selection")
Me.JobNumber.SetFocus
End If
DoCmd.OpenForm stFormName, , , "JobNumber=" & Me.JobNumber

Exit_ComboFormList_Click:
Exit Sub

Err_ComboFormList_Click:
MsgBox Err.Description
Resume Exit_ComboFormList_Click

End Sub

Everything works as I want except if user goes to form selection combo box
and tries to make a selection, they get error message in code and the focus
is set to JobNumber text box, AND THEN there is another error "Syntax error
(missing operator) in query expression 'JobNumber='."

If user puts job numberin the text box first, there is no error message. Is
there a way to stop the second error message? I'm not sure what I'm missing
here.

Any help is greatly appreciated!!
Thanks in advance!
Phisaw
 
That's because your OpenForm statement is getting executed regardless of
whether or not you're selected a job number. Use the Else part of the If
construct:

If IsNull(JobNumber) Then
MsgBox ("Please enter job number before making selection")
Me.JobNumber.SetFocus
Else
DoCmd.OpenForm stFormName, , , "JobNumber=" & Me.JobNumber
End If
 
Thanks, Doug. It works perfect!!

Douglas J Steele said:
That's because your OpenForm statement is getting executed regardless of
whether or not you're selected a job number. Use the Else part of the If
construct:

If IsNull(JobNumber) Then
MsgBox ("Please enter job number before making selection")
Me.JobNumber.SetFocus
Else
DoCmd.OpenForm stFormName, , , "JobNumber=" & Me.JobNumber
End If
 

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

Similar Threads


Back
Top