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

Printing one Record

P: 5
I am triyng to print the current record using this but when i hit the button another record was printed.
Expand|Select|Wrap|Line Numbers
  1. Private Sub PRINT_Click()
  2. On Error GoTo Err_PRINT_Click
  3.  
  4. Dim MyForm As Form
  5. Dim record_num As Long
  6.  
  7. stDocName = "PerformancePay"
  8. Set MyForm = Screen.ActiveForm
  9. DoCmd.SelectObject acForm, stDocName, True
  10. record_num = MyForm.CurrentRecord
  11. DoCmd.PrintOut acPages, record_num, record_num
  12.  
  13.  
  14. Exit_PRINT_Click:
  15. Exit Sub
  16.  
  17. Err_PRINT_Click:
  18. MsgBox Err.Description
  19. Resume Exit_PRINT_Click
  20.  
  21. End Sub
Sep 3 '08 #1
Share this Question
Share on Google+
8 Replies


Expert Mod 2.5K+
P: 2,545
Hi. There is no obvious fault with what you have, although if your command button is on the same form you don't need to use screen.activeform - you can just refer to me.currentrecord instead.

Try the following and see if it still gives you the wrong page:

DoCmd.PrintOut acSelection

(you don't need to specify the page for this option, so comment out or remove lines 8-10 above).

-Stewart
Sep 3 '08 #2

P: 5
Now i can print the current record but now is printing 3 extra pages one with the command buttons and the other two with the color background
Sep 4 '08 #3

Expert Mod 2.5K+
P: 2,545
Hi. DoCmd.Printout is intended to print the form as it appears on screen - complete with buttons and so on. The acPages qualifier you used originally restricts printing to specific pages of the form, but you indicated that it was printing the wrong record (it works fine for me on my test system).

You could revert to your original code, substituting me.currentrecord for your myform reference to screen.activeform and leaving out lines 8-10 to see what happens this time, as below:

record_num = me.currentrecord
DoCmd.PrintOut acPages, record_num, record_num


-Stewart
Sep 4 '08 #4

P: 5
Hi. DoCmd.Printout is intended to print the form as it appears on screen - complete with buttons and so on. The acPages qualifier you used originally restricts printing to specific pages of the form, but you indicated that it was printing the wrong record (it works fine for me on my test system).

You could revert to your original code, substituting me.currentrecord for your myform reference to screen.activeform and leaving out lines 8-10 to see what happens this time, as below:

record_num = me.currentrecord
DoCmd.PrintOut acPages, record_num, record_num


-Stewart
You say 8 thru 10 0r 8 and 10
Sep 4 '08 #5

Expert Mod 2.5K+
P: 2,545
8 through 10 - no need at all to select the form specifically, or set myform to screen.activeform, or set rec_num to the value of myform.currentrecord.

-Stewart
Sep 4 '08 #6

P: 5
This what i have so far and is printing one page with out buttons but the wrong record.
Expand|Select|Wrap|Line Numbers
  1. Private Sub PRINT_Click()
  2. On Error GoTo Err_PRINT_Click
  3.  
  4. Dim MyForm As Form
  5. Dim record_num As Long
  6.  
  7. stDocName = "PerformancePay"
  8. record_num = Me.CurrentRecord
  9. DoCmd.PrintOut acPages, record_num, record_num
  10.  
  11.  
  12. Exit_PRINT_Click:
  13. Exit Sub
  14.  
  15. Err_PRINT_Click:
  16. MsgBox Err.Description
  17. Resume Exit_PRINT_Click
  18.  
  19. End Sub
Sep 4 '08 #7

P: 5
Please i still with the same problem
Sep 4 '08 #8

Expert Mod 2.5K+
P: 2,545
Sorry, I can suggest no more as this appears to be something specific to your particular form in your particular circumstances.

You could devise a proper report for your users then print that using DoCmd.OpenReport, supplying a WHERE clause to filter the records and restrict printing to just the one record. That is what I do myself; I do not use the form-based PrintOut at all. I must leave further investigation of that kind of option to you however.

-Stewart
Sep 4 '08 #9

Post your reply

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