By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,312 Members | 1,723 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,312 IT Pros & Developers. It's quick & easy.

Conditional statement stopped working...

100+
P: 135
Expand|Select|Wrap|Line Numbers
  1.  If IsNull(Me![Text77]) And Me.Check107 = False And
  2.  Me.Check111 = False Then
  3. MsgBox "Enter the number of copies to print and try again. "
  4. Exit Sub
  5. Else
  6. DoCmd.PrintOut acPrintAll, , , , Me.Text77
  7. 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.
May 20 '09 #1
Share this Question
Share on Google+
7 Replies


Denburt
Expert 100+
P: 1,356
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.
May 20 '09 #2

100+
P: 135
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.
Expand|Select|Wrap|Line Numbers
  1.  If IsNull(Me![Text77]) Then
  2. MsgBox "Enter the number of copies to print and try again. "
  3. Exit Sub
  4. Else
  5. DoCmd.PrintOut acPrintAll, , , , Me.Text77
  6. 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).
May 20 '09 #3

Denburt
Expert 100+
P: 1,356
Try this
Expand|Select|Wrap|Line Numbers
  1.  if Me.Check107 = False And
  2.  Me.Check111 = False Then
  3. MsgBox "Please select the type of printout you want. "
  4. Exit Sub
  5. end if
  6.  
  7. If len(Me![Text77])=0 Then
  8. MsgBox "Enter the number of copies to print and try again. "
  9. Exit Sub
  10. Else
  11. DoCmd.PrintOut acPrintAll, , , , Me.Text77
  12. End If 
May 20 '09 #4

100+
P: 135
@Denburt
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?
May 21 '09 #5

100+
P: 135
Expand|Select|Wrap|Line Numbers
  1. 'The outputs for Check.107 and Check.111 come before this. 
  2.  
  3. If Len(Me![Text77]) = 0 And Me.Check107 = False 
  4. And Me.Check111 = False Then
  5.    MsgBox "Please select the type of printout you want. "
  6.    Exit Sub
  7.    Else
  8.  
  9. If Len(Me![Text77]) = 0 Then
  10. Exit Sub
  11. End If
  12. DoCmd.PrintOut acPrintAll, , , , Me.Text77
  13. End If
  14. 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?)
May 21 '09 #6

Denburt
Expert 100+
P: 1,356
Looks fine glad you got it and happy to be of help.
May 21 '09 #7

NeoPa
Expert Mod 15k+
P: 31,707
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?
May 25 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.