Share via

Run-time error 3075 syntax error (missing operator)

Anonymous
2013-04-01T14:11:46+00:00

I am working in MS Access 2010 and get a run time error message when the SQL statement runs. The SQL code is pulling data from a combo box (named Combo11) and then I want to use the selection to populate a subform which is part of another form. The SQL code is as follows:

Private Sub Combo11_AfterUpdate()

Dim sTestSQL As String

sTestSQL = "SELECT * FROM PerftoGoal2013_tbl WHERE [MSA Code] = " & Me.Combo11.Column(2)

Me.RecordSource = sTestSQL

Me.PerftoGoal2013_subform.Requery

End Sub

The Me.RecordSource = StestSQL is highlighted

Microsoft 365 and Office | Access | For home | 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

14 answers

Sort by: Most helpful
  1. ScottGem 68,810 Reputation points Volunteer Moderator
    2013-04-01T18:33:14+00:00

    Here's my problem. The message says that it can't find the Recordsource. No I don't know if it is the default Recordsource or what?

    If you you try to reference a column in a Combo's RowSource that doesn't exist, it should return a Null. That's why the error message showing 42F bothers me.

    1 person found this answer helpful.
    0 comments No comments
  2. ScottGem 68,810 Reputation points Volunteer Moderator
    2013-04-01T14:16:57+00:00

    Is the value in the 3rd column of Combo11's RowSource a numeric datatype? If it is try:

    sTestSQL = "SELECT * FROM PerftoGoal2013_tbl WHERE [MSA Code] = " & Me.Combo11.Column(2) & ";"

    Also is Combo11 on the subform?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2013-04-01T15:48:20+00:00

    Ok, I think we are getting closer. The combo box has two columns. Column 1 contains a msa name and column 2 has the msa code that I am using as my filter to change the Recordsource of the sub form. This is why I chose column 2. Combo 11 is on the main form.

    I changed the code and am now getting the following error message:

    run-time error 2580:

    The record source 'SELECT * FROM PerftoGoal2013_tbl WHERE [MSA Code] = '42F';' specified on this form or report does not exist.

    Here is the current SQL code:

    Dim sTestSQL As String

    sTestSQL = "SELECT * FROM PerftoGoal2013_tbl WHERE [MSA Code] = '" & Me.Combo11.Column(2) & "';"

    Me.PerftoGoal2013_subform.Form.RecordSource = sTestSQL

    Me.PerftoGoal2013_subform.Requery

    End Sub

    0 comments No comments
  4. ScottGem 68,810 Reputation points Volunteer Moderator
    2013-04-01T14:52:12+00:00

    OK, well that makes two problems with your code. First, when using the column property, the column count begins with zero. So if you want to reference the second column you have to use a 1 not a 2. 

    Second, if you are concatenating a text value into your SQL statement you need to surround it with single quotes. Try:

    sTestSQL = "SELECT * FROM PerftoGoal2013_tbl WHERE [MSA Code] = '" & Me.Combo11.Column(1) & "';"

    You also didn't answer where the controls are. The code you have, refers to Combo11 being on the active form and you are changing the Recordsource of the active form. But then you are requery a subform. 

    If your goal is to change the Recordsource of the subform, then your code should be:

    Me.PerftoGoal2013_subform.Form.Recordsource = sTestSQL

    I'm assuming that combo11 is still on the main form.

    0 comments No comments
  5. Anonymous
    2013-04-01T14:37:12+00:00

    Scott, the combo box has two columns and they are both text fields. The combo box is on the header of the main form and I want to use the selection to drive the results in the subform below. I am pulling the data from a table (PerftoGoal2013) and it contains the MSA Code along with some other information which will appear in the subform.

    0 comments No comments