Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2011
    Posts
    5

    Unanswered: Printing Single Record from Form to Report

    Hi!

    I have searched the web inside and out and I can not seem to resolve this problem.

    I have a database with three tables:
    Table 1 - Roster which contains names, grade, team and ID (autokey for Primary Key).
    Table 2 - TardyTable contains date, time, typeoftardy (looked up from AbsenceTypes), TardyID (autokey for Primary) and ID.
    Table 3 - Absence Types holds the acceptable excuses for being tardy.

    The only relationship existing is a one-to-many from Table 1 to Table 2.

    The only form in the db has an unbound dropdown box to identify the student and bring up all records related to the student and a subform from Table 2.

    I am attempting to create a button to print a report based on data entered into this subform without having to enter the parameter.

    The current code is:
    Private Sub PrintPass_Click()
    DoCmd.OpenReport "TardyPass", acViewPreview, , "[ID]=" & Me.[ID]

    End Sub


    This code brings up a dialog box to "Enter Parameter Value" and "ID". If I enter the proper ID I do get the report.

    Thanks in advance for taking the time to help,

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try Me.id or [ID] in place of me.[ID]
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2011
    Posts
    5
    Thanks for the quick response!

    I tried:

    DoCmd.OpenReport "TardyPass", acViewPreview, , "[ID]=" &Me.id

    and

    DoCmd.OpenReport "TardyPass", acViewPreview, , "[ID]=" & [ID]

    Continue to get parameter window to pop up.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. is ID the name of a column of the RecordSource of the report?
    2. If 1. = yes, is ID of type Numeric (otherwise it should be "[ID]='" & Me.ID.Value & "'"
    3. What's the value of ID before opening the report?
    (place a breakpoint [F9] on the line DoCmd.OpenReport... and when the code stops executing, open the immediate windows [CTRL+G] and type: ? Me.ID.Value)

    Note: I prefer to fully qualify the references I use (hence Me.ID.Value) but Me.ID is all right.
    Have a nice day!

  5. #5
    Join Date
    Jul 2011
    Posts
    5
    Sinndho,

    The db is at work and I am at home, but will answer what I can without being in front of it.

    1) ID is the primary key field that is an autonumber for Table 1 - Roster, which contains student names, grade and their team.

    2) It is a number.

    3) I am not sure what you mean with regard to a breakpoint - do I just push the F9 button after the DoCmd.OpenReport line or do you mean to place ID within brackets - [ID]? If you mean the later than I have done that with the same result; if you meant the first please explain further

    I appreciate your time and suggestions.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    About the breakpoint: place the cursor on the line where you want to place one (here DoCmd...), then press the F9 key. The background of the line will turn to dark red (or brownish). Restart the application and try to print the report. The execution of the code will stop at the line where you placed the breakpoint. Press CTRL+G to open the immediate window and type ? Me.ID.Value into it (? is a shortcut for print in the immediate window) then hit the enter key. The contents (value) of ID should be printed on the next line. The purpose of this is to be sure that ID contains a usable value.
    Have a nice day!

  7. #7
    Join Date
    Jul 2011
    Posts
    5
    The code screen did show red when I pressed F9.

    I restarted the app and pushed the printer button. The code ran as normal with no stops.

    The parameter pop up came up, I just pushed "OK" and the report ran. After CTRL+G and typing ? Me.ID.Value I received a "Compile error: Variable not yet created in report"

    I re-ran the report entering "1" in the parameter pop-up, and received the same compile error.
    Last edited by schooladmin; 07-20-11 at 09:19.

  8. #8
    Join Date
    Jul 2011
    Posts
    5
    I figured it out!

    My first time running subforms and the report I was running did not have a subreport! Added the subreport, based/linked by ID.

    Re-ran my script and Ta-Da! it worked!

    Thank you for all the help and patience!

Posting Permissions

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