Results 1 to 9 of 9
  1. #1
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23

    Print a report from current recordset with no fields

    Hi folks. Desperate and weekend in sight, i can not stop until i fix this. Please bear with me...

    - I am on a subform that fetches some data from excel files. (Functions like a search form)
    - With the submit button, i put the search results into the table with a recordset. (code below)

    ALL THIS WORKS FINE! Now, i want to print a report. From the same record im just added with the code below.
    How can i do this? As im not currently on a form that has no record_ID (because its for searching only)

    How do i print out the form, with the current "item_ID" (the one i just added)

    Private Sub Submit_Click()
    Dim db As Database
    Dim rec As Recordset

    Set db = CurrentDb
    Set rec = db.OpenRecordset("Select * from inboundreturns_items")

    rec.AddNew
    rec("returnID") = Forms!inboundreturns.returnID.Value
    rec("ireq") = Me.ireq
    rec("item") = Me.item
    rec("tasknumber") = Me.tasknumber
    rec("country") = Me.country
    rec("engineername") = Me.engineer
    rec("connote") = Me.connote
    rec("status") = Me.status

    rec.Update
    Set rec = Nothing
    Set db = Nothing


    End Sub




    (FYI: The report is based on the table inboundreturns_items)

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You can populate a field with: DLookup("Max(Item_ID)","inboundreturns_items","ret urnID=" & Forms!inboundreturns.returnID.Value

  3. #3
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23
    Awesome! Thanks aytee111 for the swift reply. Im grateful.

    So i enter your code into the code i put up there? Or after that along with my report printout code?
    Something like:


    Private Sub Submit_Click()


    Dim db As Database
    Dim rec As Recordset
    Set db = CurrentDb
    Set rec = db.OpenRecordset("Select * from inboundreturns_items")
    rec.AddNew
    rec("returnID") = Forms!inboundreturns.returnID.Value
    rec("ireq") = Me.ireq
    rec("item") = Me.item
    rec("tasknumber") = Me.tasknumber
    rec("country") = Me.country
    rec("engineername") = Me.engineer
    rec("connote") = Me.connote
    rec("status") = Me.status
    rec.Update
    Set rec = Nothing
    Set db = Nothing



    DLookup("Max(Item_ID)","inboundreturns_items","ret urnID=" & Forms!inboundreturns.returnID.Value


    DoCmd.OpenReport "report1", acPreview, , "item_ID = " & Me!returnID
    Exit_print_report_Click:
    Exit Sub
    Err_print_report_Click:
    MsgBox Err.Description
    Resume Exit_print_report_Click

    End Sub

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You need a variable name, or a textbox, some place to store the value.
    Dim ItemID as Long (if that is what it is)
    ItemID=Dlookup...
    Then open the report either with this ItemID or the return ID - not sure what you are doing there.

  5. #5
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23
    Thanks for sticking with me. Im not the logically smart person there is :P
    I tried a bunch of things. I thought i had it almost..but somethings off....

    Now im stuck with this. It says "cant find the field "item_ID" referred to in your expression"
    I did like you said and added a field to the search form to store the value. Called "returnidfield"


    ....
    Dim returnidfield As Long
    DLookup ("Max(item_ID)"), "inboundreturns_items", "returnID=" & Forms!inboundreturns.returnID.Value

    DoCmd.OpenReport "report1", acPreview, , "item_ID = " & Me!item_ID
    Exit_print_report_Click:
    Exit Sub
    Err_print_report_Click:
    MsgBox Err.Description
    Resume Exit_print_report_Click


    You were right, i made a mistake. Im trying to print according to item_ID.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Dim ItemID AS Long
    ItemID=DLookup ("Max(item_ID)"), "inboundreturns_items", "returnID=" & Forms!inboundreturns.returnID.Value
    DoCmd.OpenReport "report1", acPreview, , "item_ID = " &
    ItemID

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Just noticed that the syntax for your DLookup is incorrect: Dlookup(......) - your closing bracket is in the wrong place, it should be at the end after the word Value, not after item_ID.

  8. #8
    themushroomking is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    23
    WOW! That totally worked! Youre a true saviour.
    Thanks for sticking it out with me here. A thousand thanks!!!!!

    For anyone interrested or in need of help, here is the final code:


    Private Sub Submit_Click()

    Dim db As Database
    Dim rec As Recordset
    Set db = CurrentDb
    Set rec = db.OpenRecordset("Select * from inboundreturns_items")
    rec.AddNew
    rec("returnID") = Forms!inboundreturns.returnID.Value
    rec("ireq") = Me.ireq
    rec("item") = Me.item
    rec("tasknumber") = Me.tasknumber
    rec("country") = Me.country
    rec("engineername") = Me.engineer
    rec("connote") = Me.connote
    rec("status") = Me.status
    rec.Update
    Set rec = Nothing
    Set db = Nothing

    Dim ItemID As Long
    ItemID = DLookup("Max(item_ID)", "inboundreturns_items", "returnID=" & Forms!inboundreturns.returnID.Value)

    DoCmd.OpenReport "report1", acPreview, , "item_ID = " & ItemID
    Exit_print_report_Click:
    Exit Sub
    Err_print_report_Click:
    MsgBox Err.Description
    Resume Exit_print_report_Click

    End Sub

  9. #9
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    YW! Glad it works

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

Similar Threads

  1. Subform current view won't print in Report
    By crvan29 in forum Forms
    Replies: 11
    Last Post: 01-30-2017, 06:40 PM
  2. Print Report from Current Record
    By hnkford in forum Reports
    Replies: 15
    Last Post: 05-22-2015, 08:08 AM
  3. Print current form with a report
    By JulieMarie in forum Access
    Replies: 1
    Last Post: 08-02-2013, 10:30 AM
  4. Resize text fields and print current page
    By cadmaster in forum Access
    Replies: 3
    Last Post: 06-08-2013, 01:37 PM
  5. Print current record to a report
    By drawc in forum Access
    Replies: 2
    Last Post: 01-15-2012, 12:48 AM

Tags for this Thread

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