Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    mylcg
    Guest

    Printing current record

    Right now I use the Like command from a query to print what record I need. I would like to print the current record that is viewed from a form. Not the form itself. Is there away to do this.

    Thanks,

    Dan from The Last Frontier

  2. #2
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Newbury, Berkshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    Dear Dan,
    The following code linked to the on click event of a button on your form should do it.
    You will need to design a report that delivers the info you require and replace the code --- strDocName = "rpt_PrnOrders" with your reports name. You will also have to modify the code --- strFilter = "tbl_Orders.OrderID = Forms!frm_Take_Orders!OrderID" to return the current record displayed on your form.


    Private Sub Cmd_Print_Current_Rec_Click()
    On Error GoTo Err_Cmd_Print_Current_Rec_Click

    Dim strDocName As String
    Dim strFilter As String

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 'Save record

    strDocName = "rpt_PrnOrders"
    strFilter = "tbl_Orders.OrderID = Forms!frm_Take_Orders!OrderID"


    DoCmd.OpenReport strDocName, acViewNormal, , strFilter

    Exit_Cmd_Print_Current_Rec_Click:
    Exit Sub

    Err_Cmd_Print_Current_Rec_Click:
    MsgBox Err.Description
    Resume Exit_Cmd_Print_Current_Rec_Click

    End Sub

    Rupert

  3. #3
    mylcg
    Guest

    Re: Printing current record

    Thanks for the help. It looks like it will work for me. Again, thanks.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printing current record

    Here's another approach for a print button on your form. This assumes that you want to print an existing report called rptCustomers for the CustomerID that matches the current record on the form. This will work in Access 97 or 2000.

    <pre>Private Sub cmdPrint_Click()
    'dim an object variable as an
    'instance of the report class object
    'named "rptCustomers"
    Dim rpt As Report_rptCustomers
    'open an instance of the report class object
    'this isn't visible at this point
    Set rpt = New Report_rptCustomers

    With rpt
    'Set the report filter to the value
    'of the current record on this form
    .Filter = "[CustomerID] ='" & [txtCustomerID] & "'"
    'turn the filter on
    .FilterOn = True
    'make the report visible
    .Visible = True
    End With
    'destroy the object variable
    Set rpt = Nothing
    End Sub</pre>

    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    I tried to implement this solution to my case but I must be doing something wrong. I have a form called "MyRecords" where I want to place a button that will allow me to print the record I am currently viewing using the report called "SingleRecord". The form reads from a query that is linking two tables.

    I apologize for taking your time and will appreciate any assistance you can give.

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printing current record

    What the form reads from isn't the issue. If you have a key field or fields in the current record on the form that will uniquely identify a record in your report, you should be able to make it work using either of the suggested approaches. If the report is based on the same query or at least on a query that returns the equivalent record, it will work because you pass it a filter or where string that limits the record to the one you want or you can actually set the recordsource for the report in code to do the same thing.

    If you post your code, we can see what might be going wrong. Otherwise, we're just guessing and have a 50% chance of guessing wrong.[img]/w3timages/icons/crazy.gif[/img]
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Tennessee
    Posts
    194
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    if you have a field in your form that is unique like an autonumber field set the query criteria of the report to this control of the form.
    them you can use a macro or code to open, print and close the report if you want

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    Thanks to you and JerryC for your prompt response.
    I am no expert on this so, this is what I'm doing: I open the form (MyRecords) in design mode. I select the command option from the Toolbox and place it where I want it. I right click over the button, select properties, and go into "On Click". I select the (...) option "Choose Builder; Code Builder" and paste the following:
    ``````````````````````
    Private Sub cmdPrint_Click()
    'dim an object variable as an
    'instance of the report class object
    'named "rptCustomers"
    Dim rpt As Report_SingleRecord
    'open an instance of the report class object
    'this isn't visible at this point
    Set rpt = New Report_SingleRecord

    With rpt
    'Set the report filter to the value
    'of the current record on this form
    .Filter = "[ActionID] ='" & [txtActionID] & "'"
    'turn the filter on
    .FilterOn = True
    'make the report visible
    .Visible = True
    End With
    'destroy the object variable
    Set rpt = Nothing

    End Sub
    ```````````````````````````
    Once again, thanks for any help!

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printing current record

    Is ActionID a numeric field? If so, take out the single quotes in this line

    .Filter = "[ActionID] ='" & [txtActionID] & "'"

    You only wrap the value in quotes when it's a string.
    Charlotte

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    Okay, I tried this again, Rupert. I can get it to print the invoices, but now I get a box asking for a Parameter value. What is that? And it still prints out all invoices. Aaaarrrggghhh!!!

  11. #11
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    I'm trying to print off a single invoice, too. I used your code, but I keep getting: Compile Error--user-defined type not defined. What does this mean? Here's my code:

    Private Sub cmdPrint_Click()
    'dim an object variable as an
    'instance of the report class object
    'named "Invoice"
    Dim rpt As Report_SingleRecord
    'open an instance of the report class object
    'this isn't visible at this point
    Set rpt = New Report_SingleRecord

    With rpt
    'Set the report fileter to the value
    'of the current record on this form
    .Filter = "[InvID]=" & [txtInvID] & ""
    'turn the filter on
    .FilterOn = True
    'make the report visible
    .Visible = True
    End With
    'destroy the object variable
    Set rpt = Nothing

    End Sub

    Also...how would you make it so you could preview it before you print it? Thanks for your help.

    Jennifer

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printing current record

    Make sure your report has a module behind it. Open it in design view and click on the code button. The module doesn't have to have anything in it but the Option Compare and Option Explicit lines, but it has to be there before it can be called in my code, so go back and save the report.

    This code does open the form in preview, that's what making it visible does. I generally attach a custom menubar to my reports so that I can print them or change the page setup without having access to the built in menubars. That gives the user the chance to be sure they're getting what they wanted and allows them to specify the printer if necessary.
    Charlotte

  13. #13
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    I still can't get it to work. It still gives me a compile error. When it does that it hightlights the first and the fifth line. Here's the code I have:

    Private Sub cmdPrint_Click()
    'dim an object variable as an
    'instance of the report class object
    'named "Invoice"
    Dim rpt As Report_SingleRecord
    'open an instance of the report class object
    'this isn't visible at this point
    Set rpt = New Report_SingleRecord

    With rpt
    'Set the report fileter to the value
    'of the current record on this form
    .Filter = "[InvID]=" & [txtInvID] & ""
    'turn the filter on
    .FilterOn = True
    'make the report visible
    .Visible = True
    End With
    'destroy the object variable
    Set rpt = Nothing

    End Sub

    Thanks.

    Jennifer

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Printing current record

    Ok, so this is the line that gets highlighted?
    <hr>Dim rpt As Report_SingleRecord<hr>
    If so then it isn't recognizing the report module. When you're in the IDE, do you see the report module in the project explorer? If not, that's the problem and you need to enter an empty shell procedure it in and then save the report. Then you should see it in the project explorer.

    If you do see it and the code still fails, something else is going on. I use this technique all the time without problems, so I know it works. That means this specific situation is causing it to fail and we'll have to work out why.
    Charlotte

  15. #15
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Printing current record

    Okay, Charlotte. Call me a complete untechnical weenie, but I don't understand "techie" lingo. What is "IDE" and what is the project explorer? Sorry.

    Jennifer

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •