Update/Insert Query with AutoNumber.. Noobie here 
Hi guys, I'm trying to do an Insert/Update VBA code into my project, but everytime I try to run it it gives this error:
Object variable or With block variable not set. It happens on both the Insert and Update.
The CustomerID is an auto-number.
Thanks for any help!!!




Hi guys, I'm trying to do an Insert/Update VBA code into my project, but everytime I try to run it it gives this error:
Object variable or With block variable not set. It happens on both the Insert and Update.
The CustomerID is an auto-number.
Thanks for any help!!!




Code:
Private Sub Save_Click()
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cno As Integer
Dim X As Integer
Forms("Reservation")!Rents.Enabled = True
If (Forms("Reservation")!FirstNameField = Null) Or _
(Len(Trim(Forms("Reservation")!FirstNameField)) = 0) Or _
(Len(Trim(Forms("Reservation")!LastNameField)) = 0) Then
MsgBox "Cannot Save - Customer has no name!"
Else
If Forms("Reservation")!CustIDField = "" Then
db.Execute "Insert Into Customer (FirstName,LastName,TelNo,Email,Street,City,State,Zip,PicID) " & _
"Values ('" & Forms("Reservation")!FirstNameField & "','" & _
Forms("Reservation")!LastNameField & "','" & _
Forms("Reservation")!TelephoneField & "','" & _
Forms("Reservation")!EmailField & "','" & _
Forms("Reservation")!StreetField & "','" & _
Forms("Reservation")!CityField & "','" & _
Forms("Reservation")!StateField & "','" & _
Forms("Reservation")!ZipField & "','" & _
Forms("Reservation")!PicIDField & "')"
Else
db.Execute "Update Customer " & _
"Set FirstName='" & Forms("Reservation")!FirstNameField & "'," & _
"LastName='" & Forms("Reservation")!LastNameField & "'," & _
"TelNo='" & Forms("Reservation")!TelephoneField & "'," & _
"Email='" & Forms("Reservation")!EmailField & "'," & _
"Street='" & Forms("Reservation")!StreetField & "'," & _
"City='" & Forms("Reservation")!CityField & "'," & _
"State='" & Forms("Reservation")!StateField & "'," & _
"Zip='" & Forms("Reservation")!ZipField & "'," & _
"PicID='" & Forms("Reservation")!PicIDField & "' " & _
"Where CustomerID=" & Forms("Reservation")!CustIDField
cno = Forms("Reservation")!CustIDField
End If
Last edited: