S
Sara
Hi, I have an unbound form that only when the user clicks submit it add the
new record to a Complaints table. Now, I am trying to enforce certain fields
such as textboxes and comboboxes. I have tried the suggestions on previous
posts such as
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.name) Then
MsgBox "Please Enter Data"
Me.name.SetFocus
Cancel = True
End If
End Sub
But it doesnt work, it still allows me to add a new record without entering
a name.
I have also tried to add the code on submit :
Private Sub Submit_Click()
On Error GoTo Err_Submit_Click
If IsNull(Name) Then
MsgBox "Please enter Terminal"
Name.SetFocus
Cancel = True
End If
If MsgBox("Are you sure you want to add a new inquiry?", vbYesNo) = vbYes Then
Dim stDocName As String
stDocName = "APPEND - DATA"
DoCmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True
Source = Null
Equipment = Null
Terminal = Null
Train = Null
Pending = Null
Comments = Null
ProblemName = Null
ProblemDescription = Null
Exit_Submit_Click:
Exit Sub
Err_Submit_Click:
MsgBox Err.Description
Resume Exit_Submit_Click
Else
Cancel = True
End If
End Sub
Whit this last code, it prompts me to enter a Name but inmediately after
that asks me if I wan to "Add a new inquiry" and If I click yes it allows me
to add it without filling the required fields. How can I correct this? what
do I need to add?
I appreciate your help
new record to a Complaints table. Now, I am trying to enforce certain fields
such as textboxes and comboboxes. I have tried the suggestions on previous
posts such as
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.name) Then
MsgBox "Please Enter Data"
Me.name.SetFocus
Cancel = True
End If
End Sub
But it doesnt work, it still allows me to add a new record without entering
a name.
I have also tried to add the code on submit :
Private Sub Submit_Click()
On Error GoTo Err_Submit_Click
If IsNull(Name) Then
MsgBox "Please enter Terminal"
Name.SetFocus
Cancel = True
End If
If MsgBox("Are you sure you want to add a new inquiry?", vbYesNo) = vbYes Then
Dim stDocName As String
stDocName = "APPEND - DATA"
DoCmd.SetWarnings False
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True
Source = Null
Equipment = Null
Terminal = Null
Train = Null
Pending = Null
Comments = Null
ProblemName = Null
ProblemDescription = Null
Exit_Submit_Click:
Exit Sub
Err_Submit_Click:
MsgBox Err.Description
Resume Exit_Submit_Click
Else
Cancel = True
End If
End Sub
Whit this last code, it prompts me to enter a Name but inmediately after
that asks me if I wan to "Add a new inquiry" and If I click yes it allows me
to add it without filling the required fields. How can I correct this? what
do I need to add?
I appreciate your help