Run time error 3077

J

J. Lund

I am new to access programming so this may be a newbie error. I have a form
that I would like the user to select a record from the database through a
combo box. However, every time I execute the findfirst statement I get the
following message:

Run-time error '3077'; Syntax error (missing operator) in expression

Here is the code I am using.

Private Sub cboTicket_Num_AfterUpdate()
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
Dim strCriteria As String
strCriteria = "Ticket Num = " & Me.[Ticket Num]
rst.FindFirst strCriteria
If Not rst.NoMatch Then
' You know the search succeeded.
End If
End Sub

Any insight to this problem would be greatly appreciated.
 
R

Rob Parker

A couple of things I can suggest here (although I must say I don't know
exactly what's causing the error you're getting - it may be the space in the
field name in strCriteria).

First, you need to use the value of the combobox as your criterion, not the
value of [Ticket Num] (which will be the value for the form's current
record). And second, you need to move to that record if/when it's found
(and if your combobox is populated from the same table/query as your form is
bound to, that will almost certainly happen). Try this:

Private Sub cboTicket_Num_AfterUpdate()
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
Dim strCriteria As String
strCriteria = "[Ticket Num] = " & cboTicket_Num
rst.FindFirst strCriteria
If Not rst.NoMatch Then
'move to the found record
Me.Bookmark = rst.Bookmark
Else
MsgBox "No record found"
End If
End Sub

Note that if [Ticket Num] is a text datatype rather than a number, you will
need to delimit the string with single quote characters, thus:
strCriteria = "[Ticket Num] = '" & cboTicket_Num & "'"

HTH,

Rob
 
J

J. Lund

That was the solution to the run time error of 3077. The code ran like a
charm. Thanks again for all of your help.


Rob Parker said:
A couple of things I can suggest here (although I must say I don't know
exactly what's causing the error you're getting - it may be the space in
the field name in strCriteria).

First, you need to use the value of the combobox as your criterion, not
the value of [Ticket Num] (which will be the value for the form's current
record). And second, you need to move to that record if/when it's found
(and if your combobox is populated from the same table/query as your form
is bound to, that will almost certainly happen). Try this:

Private Sub cboTicket_Num_AfterUpdate()
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
Dim strCriteria As String
strCriteria = "[Ticket Num] = " & cboTicket_Num
rst.FindFirst strCriteria
If Not rst.NoMatch Then
'move to the found record
Me.Bookmark = rst.Bookmark
Else
MsgBox "No record found"
End If
End Sub

Note that if [Ticket Num] is a text datatype rather than a number, you
will need to delimit the string with single quote characters, thus:
strCriteria = "[Ticket Num] = '" & cboTicket_Num & "'"

HTH,

Rob


J. Lund said:
I am new to access programming so this may be a newbie error. I have a
form that I would like the user to select a record from the database
through a combo box. However, every time I execute the findfirst
statement I get the following message:

Run-time error '3077'; Syntax error (missing operator) in expression

Here is the code I am using.

Private Sub cboTicket_Num_AfterUpdate()
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
Dim strCriteria As String
strCriteria = "Ticket Num = " & Me.[Ticket Num]
rst.FindFirst strCriteria
If Not rst.NoMatch Then
' You know the search succeeded.
End If
End Sub

Any insight to this problem would be greatly appreciated.
 

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