Coding question

Hi Experts,
I have a question regarding the message when user try to print a report.  I have a pop up form for user to enter the criteria in order to print out a report, below is my coding:

  If C1 = False And C2 = False And C3 = False And C4 = False And C5 = False And C6 = False And C7 = False And C8 = False  And C9 = False Then
        MsgBox "Please select a type."
        Exit Sub
     End If
   
    If IsNull(DNo) Or IsNull(showDate) Then
       MsgBox "Please enter all informations before proceeding."
       Exit Sub
       
       If (C8 = True And IsNull(IncDate) Or IsNull(IncLoc)) Or (C9 = True And IsNull(IncLoc)) Then
          MsgBox "Please enter all informations before proceeding."
          Exit Sub
       End If
    Else
       stDocName = "rptshowtest"
       DoCmd.OpenReport stDocName, acNormal    
    End If

I have check boxes fro c1 to c9, however, from c1 to c7, user only need to enter "DNo" and "ShowDate", c8 user need to enter "DNo, showdate, IncDate, IncLoc" and c9 user need to enter "Dno, showDate, IncLoc".  The code I have above, it skip the second message, if I enter DNo and ShowDate then check C8, the message did not pop up and the report was printing.  can someone help?  Thanks
urjudoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I'd think you'd need this:

     If C1 = False And C2 = False And C3 = False And C4 = False And C5 = False And C6 = False And C7 = False And C8 = False And C9 = False Then
        MsgBox "Please select a type."
        Exit Sub
    End If

    If IsNull(DNo) Or IsNull(showDate) Then
        MsgBox "Please enter all informations before proceeding."
        Exit Sub
    End If
    
    If (C8 = True And IsNull(IncDate) Or IsNull(IncLoc)) Or (C9 = True And IsNull(IncLoc)) Then
        MsgBox "Please enter all informations before proceeding."
        Exit Sub
    End If
    
    stDocName = "rptshowtest"
    DoCmd.OpenReport stDocName, acNormal

Open in new window

Essentially, you're exiting the Sub after each "check", so the only way you'd get to that OpenReport call would be if all the previous checks validate.
0
PatHartmanCommented:
The third If starting with  --  If (C8 = True  -- will never be executed since it immediately follows an Exit sub.
0
urjudoAuthor Commented:
I tried Scott McDaniel's suggestion,
  If (C8 = True And IsNull(IncDate) Or IsNull(IncLoc)) Or (C9 = True And IsNull(IncLoc)) Then
        MsgBox "Please enter all informations before proceeding."
        Exit Sub
    End If
work for C8
but
If IsNull(DNo) Or IsNull(showDate) Then
        MsgBox "Please enter all informations before proceeding."
        Exit Sub
    End If
is not work for from C1 to C7, even I entered the ShowDate, it still gave the message.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

PatHartmanCommented:
If C1 = False And C2 = False And C3 = False And C4 = False And C5 = False And C6 = False And C7 = False And C8 = False  And C9 = False Then
         MsgBox "Please select a type."
         Exit Sub
End If

If IsNull(DNo) Or IsNull(showDate) Then
        MsgBox "Please enter all informations before proceeding."
        Exit Sub
End If

If C9 = True or C8 = True Then
    If IsNull(IncLoc) Then
        MsgBox "Please enter Location before proceeding."
        Me.IncLoc.SetFocus
        Exit Sub
    End If
End If

If C8 = True Then
    If IsNull(IncDate) Then
        MsgBox "Please enter Inc Date before proceeding."
        Me.IncDate.SetFocus
        Exit Sub
    End If
End if    

Open in new window


It isn't clear whether these checkboxes are mutually exclusive or not.  If they are, they should be a single Option Group control with 9 options rather than 9 separate checkboxes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
try this


 If C1 = False And C2 = False And C3 = False And C4 = False And C5 = False And C6 = False And C7 = False And C8 = False And C9 = False Then
        MsgBox "Please select a type."
        Exit Sub
     End If
     
  If IsNull(DNo) Or IsNull(showDate) Then
       MsgBox "Please enter all informations before proceeding 1."
       Exit Sub
       
       ElseIf (C8 = True And IsNull(IncDate) Or IsNull(IncLoc)) Or (C9 = True And IsNull(IncLoc)) Then
          MsgBox "Please enter all informations before proceeding 2."
          Exit Sub
       'End If
    Else
        stDocName = "rptshowtest"
       DoCmd.OpenReport stDocName, acNormal
     
    End If
0
urjudoAuthor Commented:
I tired PatHartman, it works, I also tried Rey Obrero, for some reason, the  
 If IsNull(DNo) Or IsNull(showDate) Then
        MsgBox "Please enter all informations before proceeding 1."
        Exit Sub
  is not working, even I enter both fields, it still gave me the message.
0
Rey Obrero (Capricorn1)Commented:
did you notice that I changed the message, there is 1 or 2 at the end of the message?

which message are you getting?
0
urjudoAuthor Commented:
Yes, I did.  it was
MsgBox "Please enter all informations before proceeding 2."

when I tried to print the C1 to C7. (I entered the DNo and did not enter the ShowDate, then I got the message1, the I entered the ShowDate and I got the message 2
0
PatHartmanCommented:
I guess I'm confused.  You said the code I rewrote worked.  It is also logically simpler than your or Rey's versions.

If you separate the If's as I did, you don't need to keep repeating the condition as you did in your code and as Rey did in his version.  If the first or second condition fails, you exit the sub so by the time you get to the third and fourth conditions, you only have the final additional fields to check.

Also notice in the last two conditions, the user gets a more specific message and I position the cursor to the field I want him to change.  You can only do that by isolating each condition as a separate expression.

If this code is in the Form's BeforeUpdate event (as it should be), you should also be cancelling the event before you exit so the record won't accidentally get saved with bad data.

So, in my applications, each individual edit check looks like:
If some condition is false then
        MsgBox "Please enter something before proceeding."
        Me.txtSomeField.SetFocus
        Cancel = True
        Exit Sub
End If 

Open in new window

0
Rey Obrero (Capricorn1)Commented:
<when I tried to print the C1 to C7. (I entered the DNo and did not enter the ShowDate, then I got the message1, the I entered the ShowDate and I got the message 2 >

so, the coding is correct.

if you think the coding is not correct,

post the rules or logic that need to be followed.
0
urjudoAuthor Commented:
for pathartman, i appreciated your answer, it works.  but i like to test different way so that in the future, i can use different way to program. also i put this code on click coz my form has the dno field, showdate field, incdate field and incloc field.
for Rey obrero,  the problem is from c1 to c7 user only need to enter dno and showdate, like i said, i entered dno abd left the showdate, it gave me the message1 which is correct but if i enter the dno and showdate and click "ok" , it should print the report but it did not print the report instead gave me message 2, the message 2 should be for c8 or c9 .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.