This code is driving me crazy
. I get a compile error: Argument not optional, which highlights the Me.Room_Number in the values portion of the SQL. I deleted that field from both the InsertInto and Values portion of the SQL, and retried. I then received the same error, with Me.Expiration_Date being highlighted. Guidance? The coding below is located on a button I currently have labeled "Add", located on the subform, next to the txtIDQuantity, which is what should trigger the looping. Before I went Gung-ho, I added the lot number to the Insert Into and Values portion of the SQL, and it looped and worked as desired, so I'm sure I am messing something up syntax wise.
Code:
Private Sub btnAddChemicals_Click()Dim strChemicalID As String
'search for aborted ChemicalID and use it, else if none then NewChemicalID
strChemicalID = Nz(DLookup("ChemicalID", "tblChemicalID"), "")
DoCmd.SetWarnings False
strChemicalID = NewChemicalID()
If strChemicalID <> "" Then
DoCmd.RunCommand acCmdSaveRecord
For i = 1 To Me.txtIDQuantity - 1
CurrentDb.Execute "INSERT INTO tblChemicalID(chemicalID, [Catalog Number], [Lot Number], [Received Date], [Expiration Date], [Room Number], [Section], [Comments], [OptionsID]) VALUES ('" & NewChemicalID() & "','" & Me.Catalog_Number & "', '" & Me.Lot_Number & "', '" & Me.Received_Date & "', '" & Me.Expiration_Date & "', '" & Me.Room_Number & "', '" & Me.Section & "', '" & Me.Comments & "', '" & Me.OptionsID & "')"
Next
End If
DoCmd.SetWarnings True
End Sub
I will give the NotInList event a shot, thanks!