Mandatory criteria entry on a form

Lynn73

Registered User.
Local time
Today, 15:06
Joined
Jun 6, 2007
Messages
25
Hi
I hope you can help. I have set up a form with 2 unbound text boxes for the user to enter a start and end date, along with an OK and cancel command buttons.

The problem is I want make BOTH dates mandatory before they can click on the OK button to run the report, at the moment it will work with a start OR an end date.

I would be greatful for any help on this matter.
 
Well, if it works will EITHER one right now, then you probably should replace the OR operator in your query (between the two txtbx references) to the AND operator.

You can also and an IF, THEN statement in the editor with a MgsBox function if either txtbxs are blank (upon click of the button).

Another idea is to just use an IF, THEN statement to disable the button if either txtbx is blank.

Another thing I am fond of when trying to notify a user that a value is required in a control is to put a BRIGHT RED label above it saying "*required field....just so they don't forget... :)
 
Thanks - I should have mentioned that the report, although it runs when only one date is entered, doesn't actually return any data as my query uses the AND operator.

I have added a warning message into my macro highlighting that both dates need to be populated for the report to work, however, I'm not sure where to point it to. My okay button already has the run macro command set up to it. Is this what you mean - How do I disable the button if the fields are not populated. Where would I find the msgbox funtion if its not part or the macro?

I've also used your suggestion about about the label with the *required field - that looks good and is very visible to the user on the form. Thanks for the tip.
Thanks again
 
You're welcome Lynn,

Regarding the macros, I have sort of favored Visual Basic ever since I learned it and as a result, I haven't used macro commands in months. They are very easy to follow, but they are cumbersome as you cannot readily view what commands are being executed because the VB module is written by Access itself. If I were you, I would drop the Macro entirely and write an "On-Click" SubRoutine, or a "GotFocus" SubRoutine, or possibly both....

Using the MgsBox with "On-Click"...
Code:
Private Sub cmdbutton_OnClick
  
  If IsNull(me.txtbox1) OR IsNull(me.txtbox2) Then
    MgsBox: "Both Dates Are Required For Your Search to be Completed"
      Else: Docmd.OpenReport ....etc, etc....
  End If

End Sub
Disable the button completely if either field is Null...
Code:
Private Sub cmdbutton_GotFocus

  If IsNull(me.txtbox1) OR IsNull(me.txtbox2) Then
    me.cmdbutton.enabled = False
  End if

End Sub
 

Users who are viewing this thread

Back
Top Bottom