Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2007
    Posts
    214

    Question Unanswered: Previewing Report for the specific record in a form

    Hi All,

    I have a form called "Claims Tracking System" where its recordsource is a table called "Claim Tracking System"

    I have a button that will preview a report based on what "record number" I type in. However, I would like to just click the button and it automatically just preview the report that corresponds with the record I am viewing in the form.

    The report recordsource is a query that enables me to enter a record number. Will I have to change the report recordsource along with new code? What would the new code be? I've tried code below but it has failed.

    My current code is:

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    Dim stDocName As String

    stDocName = "Eligibility Protest Letter"
    DoCmd.OpenReport stDocName, acPreview



    This is what I have tried and it fails:

    DoCmd.OpenReport "Contest letter", acViewPreview, , _
    "[record_number] = " & Forms![Claims Tracking System]![record_number]

    The above code displays no data, or I get a prompt to "enter the record_number"

    Thanks for any help!

  2. #2
    Join Date
    Jan 2009
    Location
    Kerala, India
    Posts
    183
    DoCmd.OpenReport "Contest letter", acViewPreview, , _
    "[record_number] = " & Forms![Claims Tracking System]![record_number]
    The above statement is correct and it should work unless you made some mistakes in the Form/control name.

    Try revising the statement as:

    Code:
    DoCmd.OpenReport "Contest letter", acViewPreview, , _
    "[record_number] = " & Me![record_number]
    www.MsAccessTips.com (Learn MS-Access Tips & Tricks)
    Learn Advanced MS-Access Programming with sample VBA Code.

    All responses are based on Access 2003/2007

  3. #3
    Join Date
    Oct 2007
    Posts
    214
    Everything seems to be correct. Now when I click my report, I get a blank report. The record number is the primary key and is set as a text field. Do I need to change anything with this?

  4. #4
    Join Date
    Oct 2007
    Posts
    214
    I got it now. I had record number as [record_number] instead of just [record number]

    I didn't realize I didn't need the underscore in there.

    Thanks for your help!

Posting Permissions

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