Checking a record before entry!

Stafford

Registered User.
Local time
Today, 09:09
Joined
Aug 20, 2002
Messages
23
I've grabbed some code in these forums and have been trying to get this one to work to my liking.
I have a form with a combo box and a txt box, I need values in both before the record is added.
Here is the code I've used to check for values


Private Sub cmdAddRecord_Click()
On Error GoTo Err_cmdAddRecord_Click


cmbBranchNumber.SetFocus
If cmbBranchNumber.Text = "" Then
txtTicketNumber.SetFocus
If txtTicketNumber.Text = "" Then
MsgBox "Please make sure you have entered all information!"
cmbBranchNumber.SetFocus
If cmbBranchNumber.Text = "'" Then
txtTicketNumber.SetFocus
If txtTicketNumber.Text = "" Then
MsgBox "Please enter ticket Number!"
End If
End If

End If
End If

DoCmd.GoToRecord , , acNewRec



Exit_cmdAddRecord_Click:
Exit Sub

Err_cmdAddRecord_Click:
MsgBox Err.Description
Resume Exit_cmdAddRecord_Click

End Sub


What I want this code to do is to check to see if values have been entered into either box.

As it is now, if I enter a value into at least one box, the record is added. How can I check to make sure values have been entered into both?
 
I am guessing that you want to ensure that cmbBranchNumber and txtTicketNumber are not empty (Null) before the user can "save" the current record?

Private Sub cmdSaveRecord_Click()

If IsNull(cmbBranchNumber) or cmbBranchNumber = "" Then
cmbBranchNumber.SetFocus
MsgBox "Please enter branch Number!"
Exit Sub
End If

If IsNull(txtTicketNumber) or txtTicketNumber = "" Then
txtTicketNumber.SetFocus
MsgBox "Please enter ticket Number!"
Exit Sub
End If

DoCmd.RunCommand acCmdSaveRecord

End Sub
 
That's exactly what I needed!

Thank you it works brilliantly :D
 

Users who are viewing this thread

Back
Top Bottom