Syntax Error Missing Operator (1 Viewer)

psyc0tic1

Access Moron
Local time
Today, 02:03
Joined
Jul 10, 2017
Messages
360
I have a form for looking up records. There is a text field on the form to put in a number that can be found in the table (tbl_data) field named 8DNumber which is a number field.

A subform in datasheet view is on the form to show the results of the search with the linked fields being 8DNumber.

I keep getting a Run-Time Error 3075 (Syntax error in query expression


What am I doing wrong with this code?
Code:
Private Sub cmdRecordSearch_Click()
    Dim strsearch As String
    Dim Task As String

    If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then
        MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
        Me.txtSearch.SetFocus
    Else
        strsearch = Me.txtSearch.Value
        Task = "SELECT * FROM tbl_data WHERE ((8DNumber Like ""*" & strsearch & "*""))"
        Me.RecordSource = Task
    End If
End Sub
 

Attachments

  • syntax.JPG
    syntax.JPG
    19.7 KB · Views: 249

plog

Banishment Pending
Local time
Today, 02:03
Joined
May 11, 2011
Messages
11,613
When you name fields starting with non letters you must use brackets around them in code:

8DNumber = [8DNumber]
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:03
Joined
Oct 29, 2018
Messages
21,358
Hi. Just a thought but try enclosing the field name with square brackets. i.e. [8DNumber]


Edit: Oops, too slow...
 

psyc0tic1

Access Moron
Local time
Today, 02:03
Joined
Jul 10, 2017
Messages
360
When you name fields starting with non letters you must use brackets around them in code:

8DNumber = [8DNumber]

So simple but eluded me... thanks guys... worked perfect
 

Users who are viewing this thread

Top Bottom