I am trying to prevent duplicates in a form entry in Access 2007
I am trying to use this code in the beforeupdate section of the form
My problem is it gives me a 2051 error(run action cancelled)
What it is likely supposed to do.
My question is how can I stop the user from saving with blank data but take them back to the form without wiping ut the info they already entered
Thanks
Keith
I am trying to use this code in the beforeupdate section of the form
Code:
Private Sub cmdClearForm_Click()
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acComboBox
ctl.Value = Null
Case acTextBox
ctl.SetFocus
ctl.Text = ""
End Select
Next ctl
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull([EnteredBy]) Then
MsgBox "Entered By: cannot be blank"
Cancel = True
ElseIf IsNull([InvoiceNumber]) Then
MsgBox "Invoice Number: cannot be blank"
Cancel = True
ElseIf IsNull([InvoiceAmount]) Then
MsgBox "Amount cannot be blank"
Cancel = True
ElseIf IsNull([TowCompany]) Then
MsgBox "Tow Company: cannot be blank"
Cancel = True
ElseIf IsNull([ClaimNumberPrefix]) Then
MsgBox "Claim Number Prefix cannot be blank"
Cancel = True
ElseIf IsNull([DOL]) Then
MsgBox "DOL: cannot be blank"
Cancel = True
ElseIf IsNull([PlateNumber]) Then
MsgBox "Plate Number: cannot be blank"
Cancel = True
ElseIf IsNull([InsuredLastName]) Then
MsgBox "Insured Last Name: cannot be blank"
Cancel = True
ElseIf IsNull([InsuredFirstName]) Then
MsgBox "Insured First Name: cannot be blank"
Cancel = True
ElseIf IsNull([AdjusterLastName]) Then
MsgBox "Adjuster Last Name: cannot be blank"
Cancel = True
ElseIf IsNull([AdjusterFirstName]) Then
MsgBox "Adjuster First Name: cannot be blank"
Cancel = True
Else
MsgBox "This record has been saved"
End If
End Sub
Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub
Private Sub Command55_Click()
'On Error GoTo Err_Command55_Click
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acNewRec
'Exit_Command55_Click:
'Exit Sub
'Err_Command55_Click:
'MsgBox ("Invoice Number Already Exists")
End Sub
Private Sub Tow_Company_BeforeUpdate(Cancel As Integer)
If [TowCompany] = "Other" Then
If IsNull([OtherTowCompany]) Then
MsgBox "Please fill in other tow company name"
End If
End If
End Sub
My problem is it gives me a 2051 error(run action cancelled)
What it is likely supposed to do.
My question is how can I stop the user from saving with blank data but take them back to the form without wiping ut the info they already entered
Thanks
Keith