I'm sure I'm missing some sort of parentheses or something simple, but here goes. I'm trying to run the code below. The basic idea is that I need to insert a record into a table and then return the Key field so that I can use it to populate another table. This was working just fine for a while, then it stopped and naturally I can't think of anything I did to make it not work. I get an Invalid Use of Null error at the bolded step. Any help would be greatly appreciated.
Dim SQL As String
Dim SpecID As Long
Dim VerifySpec As Variant
' Check for empty strings
If Len(Me.txtNewPartNumber & vbNullString) = 0 Then
Response = MsgBox("Part Number cannot be blank.", vbExclamation, "Missing Data")
Exit Sub
End If
If Len(Me.txtNewOperation & vbNullString) = 0 Then
Response = MsgBox("Operation cannot be blank.", vbExclamation, "Missing Data")
Exit Sub
End If
If Len(Me.txtNewMeasurement & vbNullString) = 0 Then
Response = MsgBox("Measurement Name cannot be blank.", vbExclamation, "Missing Data")
Exit Sub
End If
' Check to see if the specification already exists
VerifySpec = DLookup("sSpecificationID", "tblSpecifications", _
"[sOperation] = '" & Me.txtNewOperation & "'" & _
" And [sPartNumber] = '" & Me.txtNewPartNumber & "'" & _
" And [sMeasurementName] = '" & Me.txtNewMeasurement & "'")
If VerifySpec > 0 Then
Response = MsgBox("The values you have entered match an existing specification. Edit that specification or create another.", vbExclamation, "Duplicate Data")
Exit Sub
End If
' Enter the values into the table
SQL = "INSERT INTO tblSpecifications (sOperation, sPartNumber, sMeasurementName) " & _
"VALUES (" & Me.txtNewOperation & ",'" & Me.txtNewPartNumber & "','" & Me.txtNewMeasurement & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL SQL
DoCmd.SetWarnings True
' Get the Autonumber SpecID from the table for the record just created
SpecID = DLookup("sSpecificationID", "tblSpecifications", _
"[sOperation] = '" & Me.txtNewOperation & "'" & _
" And [sPartNumber] = '" & Me.txtNewPartNumber & "'" & _
" And [sMeasurementName] = '" & Me.txtNewMeasurement & "'")
Dim SQL As String
Dim SpecID As Long
Dim VerifySpec As Variant
' Check for empty strings
If Len(Me.txtNewPartNumber & vbNullString) = 0 Then
Response = MsgBox("Part Number cannot be blank.", vbExclamation, "Missing Data")
Exit Sub
End If
If Len(Me.txtNewOperation & vbNullString) = 0 Then
Response = MsgBox("Operation cannot be blank.", vbExclamation, "Missing Data")
Exit Sub
End If
If Len(Me.txtNewMeasurement & vbNullString) = 0 Then
Response = MsgBox("Measurement Name cannot be blank.", vbExclamation, "Missing Data")
Exit Sub
End If
' Check to see if the specification already exists
VerifySpec = DLookup("sSpecificationID", "tblSpecifications", _
"[sOperation] = '" & Me.txtNewOperation & "'" & _
" And [sPartNumber] = '" & Me.txtNewPartNumber & "'" & _
" And [sMeasurementName] = '" & Me.txtNewMeasurement & "'")
If VerifySpec > 0 Then
Response = MsgBox("The values you have entered match an existing specification. Edit that specification or create another.", vbExclamation, "Duplicate Data")
Exit Sub
End If
' Enter the values into the table
SQL = "INSERT INTO tblSpecifications (sOperation, sPartNumber, sMeasurementName) " & _
"VALUES (" & Me.txtNewOperation & ",'" & Me.txtNewPartNumber & "','" & Me.txtNewMeasurement & "')"
DoCmd.SetWarnings False
DoCmd.RunSQL SQL
DoCmd.SetWarnings True
' Get the Autonumber SpecID from the table for the record just created
SpecID = DLookup("sSpecificationID", "tblSpecifications", _
"[sOperation] = '" & Me.txtNewOperation & "'" & _
" And [sPartNumber] = '" & Me.txtNewPartNumber & "'" & _
" And [sMeasurementName] = '" & Me.txtNewMeasurement & "'")