1

I get 3075 error running this line in vba access:

Dim sqlMZG As String
sqlMZG = "SELECT MAZeitenGesamt.* Where MAZeitenGesamt.MA = 'JPA' FROM MAZeitenGesamt;"

Where JPA is a constant value. I tried the following forms and none of them worked.

SELECT MAZeitenGesamt.* Where MAZeitenGesamt.[MA] = '" & "JPA" & "' FROM MAZeitenGesamt;

SELECT MAZeitenGesamt.* Where MAZeitenGesamt.MA = '" & "JPA" & "' FROM MAZeitenGesamt;

SELECT MAZeitenGesamt.* Where MAZeitenGesamt.MA = ""JPA"" FROM MAZeitenGesamt;

SELECT MAZeitenGesamt.* Where MAZeitenGesamt.MA = \"JPA\"  FROM MAZeitenGesamt;

SELECT MAZeitenGesamt.* Where MAZeitenGesamt.MA = \'JPA\' FROM MAZeitenGesamt;

Any ideas?

3
  • 8
    the proper format for a query is like this: "SELECT * FROM tbl WHERE something = x" so in your case: "SELECT MAZeitenGesamt.* FROM MAZeitenGesamt WHERE MAZeitenGesamt.MA = 'JPA'" Commented Aug 12, 2016 at 10:16
  • @gizlmeier -- I'd recommend you add that as an answer, as I think you have correctly addressed Mary's issue Commented Aug 12, 2016 at 11:44
  • @gizlmeier the problem was what u said. do u wanna send it as an answer? Commented Aug 15, 2016 at 13:46

1 Answer 1

2

I'd recommend you use a parameter rather than quoting a literal. That said, @gizlmeier is right, in that your syntax is wrong to begin with.

Dim sqlMZG As String
sqlMZG = "parameters [MAParam] text; " & _
  "SELECT MAZeitenGesamt.* FROM MAZeitenGesamt Where MAZeitenGesamt.MA = [MAParam];"

From there, when you create your query you can set the value for the parameter:

Set qry = CurrentDb.CreateQueryDef("GetMaz", sqlMZG)
qry.Parameters("MAParam") = JPA

No messy quoting to worry about and such.

Sign up to request clarification or add additional context in comments.

2 Comments

That is: qry.Parameters("MAParam") = "JPA"
Oh, it's a literal? I thought JPA was a variable containing the actual value... my bad. If it's a literal, then the parameter isn't quite as helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.