Check empty fields on a report selection form

PascalZ

New Member
Joined
Mar 17, 2003
Messages
10
I use a form the make a report selection. How can I check fields on a report selection form? No fields are allowed to be empty when hitting the OK button to start the report.

Thanks in advance.

Pascal.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
you can uase something like
If IsNull(Me![MyCriteriaField]) Then Exit Sub
at the start of the code that prints the report.

HTH

Peter
 
Upvote 0
Also put in a message box before the exit so the user knows why, I corrected the code a little "Bat". This will only work for a single text box however. It will need more code to check all the boxes.

If IsNull(Me![Text1]) Then

MsgBox "You must fill in All Fields", vbOKOnly


Exit Sub
End If


Ziggy
 
Upvote 0
I played around with it a little to check for more than one, this example works with 3 textboxes so modify it based on your form.

Private Sub Command0_Click()

'
If (IsNull(Text1) Or Text1 = "") Or (IsNull(Text3) Or Text3 = "") _
Or (IsNull(Text5) Or Text5 = "") Then

MsgBox "You must fill in All Fields", vbOKOnly

End If

' your code.....

End Sub
 
Upvote 0
I would like to interject a quality control rant. By absolutely no means is this an expression of disrespect to Ziggy, who without any doubt is merely being concise and saving time in the reply, and besides is not being paid for his volunteer work here (I presume :) ):

Consider changing
If (IsNull(Text1) Or Text1 = "") Or (IsNull(Text3) Or Text3 = "") _
Or (IsNull(Text5) Or Text5 = "") Then
MsgBox "You must fill in All Fields", vbOKOnly
to
If (IsNull(Text1) Or Text1 = "") Then
MsgBox "report aborted because Text1 is empty in form Foo", vbOKOnly
exit sub
endif
If (IsNull(Text3) Or Text3 = "") Then
MsgBox "report aborted because Text3 is empty in form Foo", vbOKOnly
exit sub
endif
(etc.)

The first way is how the company "Yes, we're lame, but we're hot shot prima donna programmers who know better than users what is best for them" Microsoft writes dialogs/error messages/message boxes.

The Antichrist would fire anyone in his company who did it the latter way instead, but there are a multitude of blatant as well as subtle reasons why it is the "right" thing to do, although not the "Microsoft" way :devilish:

Again, I'm sure Ziggy's real-world message boxes are adequate for his users. I just want to make this important point so it can ride together with the rest of the thread in posterity (grin)
 
Upvote 0
Ziggy, in looking at your tweaked solution, I wondered if there might be an issue with "order of evaluation." Is is okay to say
If (IsNull(Text1) Or Text1 = "") Then

or does it need to say
If not IsNull(Text1) then
if Text1 <> "" Then
bIsProblem=False
(etc.)
There are several ways to do this; the point is to (1.) check for Null first, and (2.) don't check for "" in the same statement.

Sure, I realize it's a disgusting, seemingly wasteful expansion of code; but I don't know if left-to-right boolean evaluation is assured. I've had VBA crap out for that very reason (perhaps with Excel, though?).

Is anyone knowledgeable on this and side effects of evaluation?
 
Upvote 0
Gates..

It all depends on how precise you want to be, if the user has 20 fields on a form than sure your solution is much more suitable. If there are only a few fields than I'm sure the "General' message would suffice.

Admitingly testing for the empty string seems irrelavant as further testing has proved. Non the less I took a stab at it, and it does the job.

*You seem to have gone out of your way to make your Point!
 
Upvote 0
Ziggy said:
Gates..
It all depends on how precise you want to be, if the user has 20 fields on a form than sure your solution is much more suitable.

...

*You seem to have gone out of your way to make your Point!
And yet he misses completely - a total airball, ROFL! If there are *two* fields there is no excuse for laziness, although you can flourish at Microsoft with that attitude :oops:
 
Upvote 0
Well I guess I'm not Perfect like You, I was merely attempting to help someone, if you had a better solution then I'm sure you could have fould a more amicable way of getting your message across.
 
Upvote 0
Relax. I tried to say - I did say - that your help is appreciated - so keep it up. Don't take constructive criticism personally. (However, if you want to go to bat for lameness, that's another matter :) )
 
Upvote 0

Forum statistics

Threads
1,221,567
Messages
6,160,541
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top