Solved

Coding question

Posted on 2014-10-23
11
206 Views
Last Modified: 2014-10-28
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
0
Comment
Question by:urjudo
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 100 total points
ID: 40400081
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
 
LVL 36

Expert Comment

by:PatHartman
ID: 40400093
The third If starting with  --  If (C8 = True  -- will never be executed since it immediately follows an Exit sub.
0
 

Author Comment

by:urjudo
ID: 40400166
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 36

Accepted Solution

by:
PatHartman earned 300 total points
ID: 40400227
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
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 100 total points
ID: 40400287
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
 

Author Comment

by:urjudo
ID: 40400426
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40400485
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
 

Author Comment

by:urjudo
ID: 40400523
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
 
LVL 36

Expert Comment

by:PatHartman
ID: 40400582
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40400616
<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
 

Author Comment

by:urjudo
ID: 40400649
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Creating a Temp Table in MS Access 5 48
Undo Button 1 35
Access Report formatting issue 5 26
How can I set my Access Query up to filter out specific records 13 28
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question