Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Query From Form Info (2002)

    Hey Gang. I have an access DB that I need to print out face sheets based on the records on the current open form. I have a query and report already that gives me information on all the info but I want to add a button that will allow me to print that report from the query with only the info pertaining to the current record. Is there a way to use the Primary Key as the filter on the report from an open record??i.e. If my form has Name, Id, Add1, Add1city, st, zip and I want it print just that info for the current user instead off all users how do I get the current ID as the filter??

    Thanks in advance,

    Dan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Query From Form Info (2002)

    Put a command button on the form.
    Give it a meaningful name and use whatever naming convention you are comfortable with. For example: cmdReport.
    With the button selected, activate the Event tab of the Properties window.
    Click in the On Click event.
    Select [Event Procedure] from the dropdown list.
    Click the builder button, i.e. the three dots to the right of the dropdown arrow.
    You will be taken to the Visual Basic Editor, with the skeleton of the event procedure already created for you, ready to be completed.
    Make it look like this, with the appropriate names substituted:

    Private Sub cmdReport_Click()
    DoCmd ReportName:="rptMyReport", View:=acViewPreview, WhereCondition:="ID = " & Me.[ID]
    End Sub

    Return to Access (Alt+F11) and close/save the form.

  3. #3
    New Lounger
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query From Form Info (2002)

    Hans thank you for your reply. I modified the code example you gave me to this:
    DoCmd.OpenReport ReportName:="rptMyReport", View:=acViewPreview, WhereCondition:="MAIL_ID = " & Me.[MAIL_ID]

    Problem now is I get 3 input boxes popping up asking 1.Mail Id, 2. Id and 3 Number. No matter what I enter the report open up blank.

    Any thoughts??

    Dan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Query From Form Info (2002)

    The parameter prompts you get mean that either there is a spelling error somewhere, or fields are lacking from the record source of the report.

    Is your primary key field really called MAIL_ID, or perhaps MAIL ID? And is it present in the record source of the report?

  5. #5
    New Lounger
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query From Form Info (2002)

    Hans, thanks again for your time on this matter. Yes the PK Field is Mail_ID. But I also tried it using another field and still got the Input Box. I used the Last Name text box named LAST. After I modified the code to use "LAST =" & ME.LAST. I still got the Input box but after entering in the the Last Name the report opened up to the correct item but I still has to enter the info in the input box.

    I will keep trying diferent things. IF you can think of anything else let me know.

    Dan

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Query From Form Info (2002)

    If you like, you can post a stripped down version of the database:
    <UL><LI>Make a copy of the database and work with that.
    <LI>Remove all database objects (tables, queries, forms, reports, macros and modules) that are not relevant to the problem.
    <LI>In the remaining table(s), remove most records - leave only the minimum number necessary to demonstrate the problem.
    <LI>Remove or modify data of a confidential nature.
    <LI>Do a compact and repair (Tools/Database Utilities).
    <LI>Make a zip file containing the database; it should be below 100KB.
    <LI>Attach the zip file to a reply.[/list]This will let others look at the problem directly.

  7. #7
    New Lounger
    Join Date
    Jan 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query From Form Info (2002)

    Hans,

    Thanks for your help I used an autonumber field and it works perfect. Not sure why the other fields are odd but I will look at those later.

    Dan

Posting Permissions

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