Share via

Syntax error (missing operator) question

Anonymous
2024-11-06T19:06:00+00:00

I have the following code in my Form Open section. It all works except one line in the middle. The line starting Me.cbo30CFRID.Value It has an error "Run-time error '3075': Syntax error (missing operator) in query expression '30CFRID'."

I cannot find where it's any different than the lines above or below. Other than it referencing 30CFRID of course. What am I missing?

The table, tblCitations, has a 30CFRID field. Again, everything else works. If I step past that line, the rest of it fires off, the form opens, and it's populated except the 30CFR line.

EDIT: So, I fixed it by adding [ ] so it's now "[30CFRID]". But could someone still explain WHY it needed brackets when the others didn't? Should I be adding the brackets to everything just in case?

    If sMode = "Edit" Then 

        lCitationID = Me.OpenArgs 

        Me.txtCitationID.Value = lCitationID 

        Me.txtCitationNumber.Value = DLookup("CitationNumber", "tblCitations", "CitationID = " & lCitationID) 

        Me.cboShiftID.Value = DLookup("ShiftID", "tblCitations", "CitationID = " & lCitationID) 

        Me.cboEmployeeID.Value = DLookup("EmployeeID", "tblCitations", "CitationID = " & lCitationID) 

        Me.txtCitationDate.Value = DLookup("CitationDate", "tblCitations", "CitationID = " & lCitationID) 

        Me.cboCategoryID.Value = DLookup("CategoryID", "tblCitations", "CitationID = " & lCitationID) 

        Me.cbo30CFRID.Value = DLookup("30CFRID", "tblCitations", "CitationID = " & lCitationID) 

        Me.cboSSOID.Value = DLookup("SSOID", "tblCitations", "CitationID = " & lCitationID) 

        Me.txtCondition.Value = DLookup("Condition", "tblCitations", "CitationID = " & lCitationID) 

        Me.txtEstimatedAssessment.Value = DLookup("EstimatedAssessment", "tblCitations", "CitationID = " & lCitationID) 

        Me.cboLocationID.Value = DLookup("LocationID", "tblCitations", "CitationID = " & lCitationID) 

        Me.cboUnitID.Value = DLookup("UnitID", "tblCitations", "CitationID = " & lCitationID) 

    End If
Microsoft 365 and Office | Access | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Duane Hookom 26,820 Reputation points Volunteer Moderator
    2024-11-06T20:02:21+00:00

    Starting a field name with a number is the problem.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Answer accepted by question author

  1. HansV 462.6K Reputation points
    2024-11-06T19:46:32+00:00

    Does it help if you use

            Me.cbo30CFRID.Value = DLookup("[30CFRID]", "tblCitations", "CitationID = " & lCitationID)
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-11-06T20:07:46+00:00

    Thank you very much.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-11-06T19:51:59+00:00

    Yes, I edited my question after testing that. With the brackets it does work. So that's good. But could you explain why that line needs brackets? Is it just because there are numbers in the name? Should I be using brackets all the time, or just worry about it when it doesn't work without the brackets?

    Was this answer helpful?

    0 comments No comments