Keith
Registered User.
- Local time
- Today, 09:25
- Joined
- May 21, 2000
- Messages
- 129
Hi
I am using an unbound form for data entry to prevent errors getting into the table i.e. if with a form bound to the table, the user exits the form having only entered one field, a record is created with that field completed only.
I use code to write the record to the table but unless the form is closed and reopened any subsequent records are not added to the table. I am probably going about this in completely the wrong way and any advice would be appreciated. Below is the code that I use.
Keith
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
'Validate Data before Save
If IsNull(Me.txtRegNo) Or Me.txtRegNo = "" Then
Call MsgBox("Registration Number is Required", vbInformation, "SAVE ERROR")
Me.txtRegNo.SetFocus
Exit Sub
End If
'Save DATA
Dim SQL As String
SQL = "INSERT INTO tblVehicle(RegistrationNo,VehicleMake,EngineMake,Seats,ChassisNo,DateRegistered,
PurchaseMileage,PurchaseDate,LicenceRenewalDate,TestDue)" &
"VALUES('" & [txtRegNo].Value & "','" & [txtVehicleMake].Value & "','" & [txtEngineMake].Value & "','" & [txtSeats].Value & "','" &[txtChassisNo].Value & "','" & [txtDateRegistered].Value & "','" & [txtPurchaseMileage].Value & "','" & [txtPurchaseDate].Value & "','" & [txtLicRenDate].Value & "','" & [txtTestDue].Value & "')" '"
DoCmd.SetWarnings False
DoCmd.RunSQL (SQL)
DoCmd.SetWarnings True
'Reset Form
Me.txtRegNo = ""
Me.txtPurchaseMileage = ""
Me.txtVehicleMake = ""
Me.txtEngineMake = ""
Me.txtChassisNo = ""
Me.txtDateRegistered = ""
Me.txtPurchaseDate = ""
Me.txtSeats = ""
Me.txtLicRenDate = ""
Me.txtTestDue = ""
Me.txtRegNo.SetFocus
DoCmd.Close
DoCmd.OpenForm "frmVehicle"
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
I am using an unbound form for data entry to prevent errors getting into the table i.e. if with a form bound to the table, the user exits the form having only entered one field, a record is created with that field completed only.
I use code to write the record to the table but unless the form is closed and reopened any subsequent records are not added to the table. I am probably going about this in completely the wrong way and any advice would be appreciated. Below is the code that I use.
Keith
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
'Validate Data before Save
If IsNull(Me.txtRegNo) Or Me.txtRegNo = "" Then
Call MsgBox("Registration Number is Required", vbInformation, "SAVE ERROR")
Me.txtRegNo.SetFocus
Exit Sub
End If
'Save DATA
Dim SQL As String
SQL = "INSERT INTO tblVehicle(RegistrationNo,VehicleMake,EngineMake,Seats,ChassisNo,DateRegistered,
PurchaseMileage,PurchaseDate,LicenceRenewalDate,TestDue)" &
"VALUES('" & [txtRegNo].Value & "','" & [txtVehicleMake].Value & "','" & [txtEngineMake].Value & "','" & [txtSeats].Value & "','" &[txtChassisNo].Value & "','" & [txtDateRegistered].Value & "','" & [txtPurchaseMileage].Value & "','" & [txtPurchaseDate].Value & "','" & [txtLicRenDate].Value & "','" & [txtTestDue].Value & "')" '"
DoCmd.SetWarnings False
DoCmd.RunSQL (SQL)
DoCmd.SetWarnings True
'Reset Form
Me.txtRegNo = ""
Me.txtPurchaseMileage = ""
Me.txtVehicleMake = ""
Me.txtEngineMake = ""
Me.txtChassisNo = ""
Me.txtDateRegistered = ""
Me.txtPurchaseDate = ""
Me.txtSeats = ""
Me.txtLicRenDate = ""
Me.txtTestDue = ""
Me.txtRegNo.SetFocus
DoCmd.Close
DoCmd.OpenForm "frmVehicle"
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click