Conditional statement stopped working...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyWaterloo
    New Member
    • Dec 2007
    • 135

    Conditional statement stopped working...

    Code:
     If IsNull(Me![Text77]) And Me.Check107 = False And
     Me.Check111 = False Then
    MsgBox "Enter the number of copies to print and try again. "
    Exit Sub
    Else
    DoCmd.PrintOut acPrintAll, , , , Me.Text77
    End If
    I was using this code to have my user receive a message informing him to enter a print amount if he left the text (Text77) field blank. I believe I had it working (I can't remember, it could have been a variation of this) and now it just runs right past the first part of the code and goes right to the DoCmd. I then get an internal error because my text field is blank. What do I do to remedy my code? Again, I would like my user to receive a message telling him to enter a print amount and then I want the event to cancel before going to the print function. Thank You.
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    What is Check107 and Check111 and why are they involved in this at all?
    If either one of those are checked as true then that is your problem. We really need more info in order to go further.

    Comment

    • MyWaterloo
      New Member
      • Dec 2007
      • 135

      #3
      I have print button. There is a box (Text77) to select the number of pages to be printed. I also have two checks: 107 is labeled "PDF" and 111 is labeled "DOC." The user can then decide to print and save his purchase order in any of the three ways. The code for the two checks comes before this code. I have even tried the code without the language for the two checks and it still won't work.
      Code:
       If IsNull(Me![Text77]) Then
      MsgBox "Enter the number of copies to print and try again. "
      Exit Sub
      Else
      DoCmd.PrintOut acPrintAll, , , , Me.Text77
      End If
      I want to be able to cancel the event and exit the sub if neither check box is true and the textbox is empty (Null).

      Comment

      • Denburt
        Recognized Expert Top Contributor
        • Mar 2007
        • 1356

        #4
        Try this
        Code:
         if Me.Check107 = False And
         Me.Check111 = False Then
        MsgBox "Please select the type of printout you want. "
        Exit Sub
        end if
        
        If len(Me![Text77])=0 Then
        MsgBox "Enter the number of copies to print and try again. "
        Exit Sub
        Else
        DoCmd.PrintOut acPrintAll, , , , Me.Text77
        End If

        Comment

        • MyWaterloo
          New Member
          • Dec 2007
          • 135

          #5
          Originally posted by Denburt
          Try this
          Code:
           if Me.Check107 = False And
           Me.Check111 = False Then
          MsgBox "Please select the type of printout you want. "
          Exit Sub
          end if
          
          If len(Me![Text77])=0 Then
          MsgBox "Enter the number of copies to print and try again. "
          Exit Sub
          Else
          DoCmd.PrintOut acPrintAll, , , , Me.Text77
          End If
          I think I didn't make myself clear. I have three options: save as PDF, save as Word DOC, or print to printer. I want to be able to select any one or combo of these 3 options. They are all fired from the same button. If none of these 3 are selected I would like a message box displayed when the button is pushed that tells the user to select some type of output before pushing the button. The problem with the above code is that if I leave the 2 checks false then it will exit the sub and won't run to my print code. If I put the code in reverse the same happens (won't run to PDF,DOC code if my print box is left empty). Did that make sense?

          Comment

          • MyWaterloo
            New Member
            • Dec 2007
            • 135

            #6
            Code:
            'The outputs for Check.107 and Check.111 come before this. 
            
            If Len(Me![Text77]) = 0 And Me.Check107 = False 
            And Me.Check111 = False Then
               MsgBox "Please select the type of printout you want. "
               Exit Sub
               Else
             
            If Len(Me![Text77]) = 0 Then
            Exit Sub
            End If
            DoCmd.PrintOut acPrintAll, , , , Me.Text77
            End If
            End If
            This works! I had to add the extra "If Len(Me![Text77]) = 0 Then Exit Sub" at the end right before the PrintOut. The reason was if one of the checks was true the code would run to the PrintOut and then error because the textbox was empty.
            Thanks for all the Help!
            (Is this the best way to go about this? It works...so that's the point...Right?)

            Comment

            • Denburt
              Recognized Expert Top Contributor
              • Mar 2007
              • 1356

              #7
              Looks fine glad you got it and happy to be of help.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32661

                #8
                I feel like I'm in a mad-house. Everyone's talking as if that code would work, yet there are half-formed If statements on lines that will never process (as far as I can see). No continuation characters anywhere to be seen, yet statements spread across multiple lines.

                Am I missing something obvious here?

                Comment

                Working...