How do I get error msg's to appear?

RichieP

Rock on!
Local time
Today, 18:40
Joined
Apr 16, 2003
Messages
48
Please help meeeeee!

How do I get error msg to appear? I have a button on a form that runs a query. The query relys on 4 text boxes to be filled with data (the first two being two date fields to show a range of dates and the second two being two integer fields showing a range for age). Once these fields are filled and the button is pressed it brings back the data no probs. If one or more of the txt boxes are not filled then the button brings back the query with no data. Instead, what I need is a msg box telling the user that not all the boxes are filled.

That should be an easy one for all you experts!:confused:

Thanks
Rich
 
On your button, you can check that the fields have data and exit the sub if any of your textboxes have no data, and returning the focus to the specific textbox in order.

Code:
If IsNull(Me.txtYourFirstField) Then
   MsgBox "You have not entered the first date.", vbExclamation, "Missing Data"
   Me.txtYourFirstField.SetFocus
   Exit Sub
End If

If IsNull(Me.txtYourSecondField) Then
   MsgBox "You have not entered the second date.", vbExclamation, "Missing Data"
   Me.txtYourSecondField.SetFocus
   Exit Sub
End If

If IsNull(Me.txtYourThirdField) Then
   MsgBox "You have not entered the first age.", vbExclamation, "Missing Data"
   Me.txtYourThirdField.SetFocus
   Exit Sub
End If

If IsNull(Me.txtYourFourthField) Then
   MsgBox "You have not entered the second age.", vbExclamation, "Missing Data"
   Me.txtYourFourthField.SetFocus
   Exit Sub
End If

DoCmd.OpenQuery "qryYourQuery
 
As an extra, if you want to inform the user at the end that there is no records, even if they have entered all the details, you can modify the last line around the opening of the query like this.

Code:
If DCount("[ID]", "qryYourQuery") = 0 Then
   MsgBox "There is no data for the information you have entered.", vbInformation, "No Records Returned."
   Exit Sub
Else
   DoCmd.OpenQuery "qryYourQuery"
End If
 
I have the first part working but the what do I need to put in the '[ID]' part?

Thanks for your reply mr duck.
 
Preferable the Primary Key field of the query - failing that, any field name.
 
Worked a treat! Thanks very much!

I like the three eyed duck by the way.

Thanks again
Rich
 
No probs.

The duck says "Thanks!"
 

Users who are viewing this thread

Back
Top Bottom