The Problem: I keep getting a syntax error for the following statement:
CurrentDb.Execute "INSERT INTO Inventory ([Part #], [Year], [Week], [In], [Out]) " _
& "VALUES ('" & Me.txtFindPart & "'," & Me.txtYear & "," & i & "," _
& Me.Controls("in" & i) & "," & Me.Controls("out" & i) & ");"
Now I have a feeling it is the Me.Controls function that keeps throwing this error but I can't get it to go away.
Context: This is for an update button, where it checks if there is a record, if the two spaces in the form are empty and if neither of these conditions are filled it will create a new record.
Now when this happens the data from textbox in# and out# are used to create the new record.
The Code:
Dim i As Integer
i = 1
Do Until i = 53
If DCount("[Part #]", "[Inventory]", "([Inventory].[Part #] = '" & txtFindPart & "' AND [Inventory].[Year] = " & txtYear & " AND [Inventory].[Week] = " & i & ")") > 0 Then
CurrentDb.Execute "UPDATE Inventory SET [In] = '" & Me.Controls("in" & i) & "' WHERE [Part #] = '" & txtFindPart & "' AND [Year] = " & txtYear & " AND [Week] = " & i & ";"
CurrentDb.Execute "UPDATE Inventory SET [Out] = '" & Me.Controls("out" & i) & "' WHERE [Part #] = '" & txtFindPart & "' AND [Year] = " & txtYear & " AND [Week] = " & i & ";"
i = i + 1
ElseIf Me.Controls("in" & i) = Null And Me.Controls("out" & i) = Null Then
i = i + 1
Else
CurrentDb.Execute "INSERT INTO Inventory ([Part #], [Year], [Week], [In], [Out]) " _
& "VALUES ('" & Me.txtFindPart & "'," & Me.txtYear & "," & i & "," _
& Me.Controls("in" & i) & "," & Me.Controls("out" & i) & ");"
i = i + 1
End If
Loop
Me.Requery
in1, in2, in3, in4...andout1, out2, out3, out4...on your form? Also do you get a specific Syntax error?CurrentDb.ExecutebyDebug.Print. This will output all your actual SQL statements into the Immediate Window. Then, edit your question and paste one or two of the SQL statements so we can see the actual SQL that is executed.