Results 1 to 9 of 9
  1. #1
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20

    Print Button for Current Record ?

    If anybody knows how to fix this Print" button, I'll be grateful!



    GOAL: Print just the displayed record.

    PROBLEM: Clicking the "Print" button . . . nothing happens.

    Form "view code":

    Private Sub cmdPrint_Click()
    'Print current record
    'using rptENVELOPE.
    If IsNull(Me!ID) Then
    MsgBox "Please select a valid record", _
    vbOKOnly, "Error"
    Exit Sub
    End If
    DoCmd.OpenReport "ENVELOPE", , , _
    "ID = " & Me!ID
    End Sub

    Click image for larger version. 

Name:	FORM VIEW CODE.jpg 
Views:	21 
Size:	50.7 KB 
ID:	44597

    FORM ("Contacts"):
    Click image for larger version. 

Name:	FORM.jpg 
Views:	19 
Size:	138.7 KB 
ID:	44600

    REPORT ("ENVELOPE"):
    Click image for larger version. 

Name:	REPORT (ENVELOPE).jpg 
Views:	19 
Size:	166.8 KB 
ID:	44599
    Attached Thumbnails Attached Thumbnails FORM.jpg  

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Made boo boo in interpretation. Another good example of why you should use code tags with proper indentation to make it easier to read.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Here we go

    Walk through your code line by line.

    It *look* OK to me, but who knows.?
    You are not expecting it to open are you, it will just print?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    Correct. Just to print.

  5. #5
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    Thanks for your reply.

    However, I do not understand the "boo boo" instructions.

    If you can fix my code, maybe that would help?

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Compare what you must have got in the email notification to what the post ended up being. I mis-read your code. I agree with Welshgasman - it looks ok from a code perspective and you need to step through it and report what happens. Put a break at the beginning and step through (by clicking your button). IF it doesn't run at all, then somehow your code is disconnected from your control. In that case, re-select the event in the property sheet for the button. All I can do at the moment to "fix" anything is the presentation, like this:
    Code:
    Private Sub cmdPrint_Click()
    'Print current record using rptENVELOPE
    
    If IsNull(Me!ID) Then
       MsgBox "Please select a valid record", vbOKOnly, "Error"
       Exit Sub
    End If
    
    DoCmd.OpenReport "ENVELOPE", , , "ID = " & Me!ID
    End Sub
    Last, I would use Me.anything (dot) not Me!anything Any Me! reference is ignored upon compile, so a misspelled reference won't get caught until run time, which will then raise an error. I also see you are not using Option Explicit. A wiser person than me once said "if you don't use Option Explicit, you deserve what you get."
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    Thanks Micron! You figured it out.

    I replaced my Form Code with YOUR code . . . and it now prints 1 record. Great.

    DIFFERENCE:

    YOUR line . . . . 'Print current record using rptENVELOPE

    MY line . . . 'Print current record using rptENVELOPE. (has a period at the end!!!)

    Well, go figure.

    Lah-dee-dah

    picky-picky-picky

    THANKS to everybody.


  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    What!!!??
    That is a comment line, should not matter a jot?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    That's definitely not the answer; something else changed. You said it didn't run at all and not only would a period at the end of a comment line not raise an error, it certainly would not cause the code to not run. How did you get to the code procedure to make the change - from the property sheet? The only other potential issue I can see is your use of the line continuation character (i.e. cannot tell if your syntax is correct, which is why you should cut and paste code within code tags) but again, that would not cause it to fail to run either.
    Last edited by Micron; 03-12-2021 at 07:04 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. error on print current record
    By mar7632 in forum Access
    Replies: 2
    Last Post: 05-10-2019, 07:07 AM
  2. How to print current record
    By hursan1710 in forum Access
    Replies: 1
    Last Post: 11-10-2016, 10:06 AM
  3. How can I print an object for the current record?
    By alexandervj in forum Access
    Replies: 3
    Last Post: 12-06-2013, 04:03 PM
  4. Print current record to a report
    By drawc in forum Access
    Replies: 2
    Last Post: 01-15-2012, 12:48 AM
  5. Replies: 5
    Last Post: 10-26-2011, 02:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums