Validate/Verify entry in MsgBox

S

Steve Stad

I have a button on a form to open a report based on a parameter query. The
button activates the parameter query and the parameter msgbox says enter MIL
or CIV. I would like to ensure the user spells MIL or CIV correctly so the
parameter query runs correctly everytime. The current button code is below.
Can you tell me how to add/edit or redo code to force user to spell MIL or
CIV correctly. For example with if statement ..If input box <> "CIV" and
inputbox <> "MIL" then msgbox "You Must spell MIL or CIV correctly"

Private Sub MILCIVPercentCompRep_Click()
On Error GoTo Err_MILCIVPercentCompRep_Click
Dim stDocName As String
stDocName = "Rep_CompletenessMIL&CIVPerc"
DoCmd.OpenReport stDocName, acPreview
Exit_MILCIVPercentCompRep_Click:
Exit Sub
Err_MILCIVPercentCompRep_Click:
MsgBox Err.Description
Resume Exit_MILCIVPercentCompRep_Click
End Sub
 
D

Daryl S

Steve -

You could put an option group on the form next to the report button that
lets them only choose MIL or CIV. Then for the parameter query, change it to
pull the value selected in the option group from the form.
 
S

Steve Stad

Thanks Daryl - that is one solution. But sometimes I run the query from the
query design window and prefer to type in MIL or CIV in the parameter window.
Can I overide the CIV MIL in the option group on the form if I run it from
w/i the Query Design mode. The idea is to prevent fat fingering and typing
CVI which causes the parameter query to run nothing or nulls.
 
J

John W. Vinson

I have a button on a form to open a report based on a parameter query. The
button activates the parameter query and the parameter msgbox says enter MIL
or CIV.

Rather than the prompt [Enter MIL or CIV] I'd strongly suggest using an
unbound combo box on your Form, and using

=[Forms]![YourFormName]![comboboxname]

as a parameter. If the form isn't open you'll get prompted.
 
S

Steve Stad

Thanks guys. I added the [FORMS]![frm_Completeness]![Combo14] in both
underlying queries and it works great. If the form is open the form controls
the qrys and if the form is closed I can over ride and type in the MIL or
CIV.

John W. Vinson said:
I have a button on a form to open a report based on a parameter query. The
button activates the parameter query and the parameter msgbox says enter MIL
or CIV.

Rather than the prompt [Enter MIL or CIV] I'd strongly suggest using an
unbound combo box on your Form, and using

=[Forms]![YourFormName]![comboboxname]

as a parameter. If the form isn't open you'll get prompted.
 
D

Daryl S

Steve -

If the form is not open, then the query will prompt for the values, though
the prompt will be something like Forms!formname!controlname - as the
developer you will recognize it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Bypass Enter Parameter Value 2
Report VB Code 1
MsgBox 7
Command button plus message 2
Run Different Reports with Same Button 4
Printing from a form 2
Help with "Where" on command button 1
filter on command 1

Top