Syntax Error on Update Statement - need another pair of eyes!

Starchildren3317

Registered User.
Local time
Today, 06:31
Joined
Nov 30, 2010
Messages
11
Good Afternoon Community -

I could really use another pair of eyes looking at my sql statement. I have an Access application with a SQL Server backend.

In the following code I am trying to update a table called Results with a value in a text box on the form and certain fields equaling certain values. The Sub kicks off after you update the text field.

Here is the code:

Code:
Private Sub txtAnalysisFilterDate_AfterUpdate()
Dim aStr As String
Const Dust = "Total Dust"
Const Niosh = "NIOSH 0500"
Const Niosh1 = "NIOSH 500"


    aStr = "UPDATE Results SET Results.EnteredDate = " & "'" & [txtAnalysisFilterDate] & "'" & "FROM (Results INNER JOIN dbo_GasSamples ON (Results.Test = dbo_GasSamples.Test) "
    aStr = aStr & "AND (Results.SampleNumber = dbo_GasSamples.SampleNumber) AND (Results.OrderID = dbo_GasSamples.OrderID)) "
    aStr = aStr & "INNER JOIN SampleDetails ON (dbo_GasSamples.OrderID = SampleDetails.OrderID) AND (dbo_GasSamples.SampleNumber = SampleDetails.SampleNumber) "
    aStr = aStr & "AND (dbo_GasSamples.Test = SampleDetails.Test) WHERE (((dbo_GasSamples.OrderID)= " & "'" & [Forms]![LibBreathingAir]![OrderID] & "'" & ") "
    aStr = aStr & "AND ((dbo_GasSamples.Test)= " & "'" & Dust & "'" & ") AND ((SampleDetails.Method)= " & "'" & Niosh & "'" & " OR (SampleDetails.Method)= " & "'" & Niosh1 & "'" & "));"

DoCmd.RunSQL aStr
End Sub

When I try to run I am getting this error:

Run-time error '3075'

Syntax error (missing operator) in query expression...

and then it lists the query. If anyone sees something I am missing or doing wrong I would greatly appreciate the feedback!

Thanks a ton!
 
I did notice that there was a missing space before the FROM keyword, but I also think that mismatched parenthesis may be an issue. Verify that they are properly matched.

UPDATE: The parentheses are matched, and should work as written
 
Last edited:
I played with the space inbetween the " and From and it didnt make a difference. I keep the space in anyway just because it reads easier.

Uncle Gizmo - Access uses '#' for dates but SQL Server does not so it cant be that.

I put a break point on the first 'aStr' line and the [txtAnalysisFilterDate] is taking the value of the text box as it should be.
 

Users who are viewing this thread

Back
Top Bottom