Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    auto fill criteria for query (2003)

    User completes a form and 'after update' of SERIAL field kicks off code to auto-print a label of data just entered using query criteria (like[ ]) based report.
    If using code below and set to acPREVIEW, record is found and preview occurs. If set to acPRINT, code "misses"
    sendkey commands and criteria/parameter window is displayed waiting for user input. Is there another way to force
    "myvalue" into criteria?
    CODE FOLLOWS:
    myvalue = Serial
    stDocName = "Report-printed"
    SendKeys myvalue
    SendKeys "{enter}"
    DoCmd.OpenReport stDocName, acPrint Ďauto print report for Serial# from previous record
    DoCmd.GoToRecord , "", acNewRec
    Forms!tbl_scanned!IN.SetFocus 'setup new record input

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

    Re: auto fill criteria for query (2003)

    One option is to refer to the form in the criteria in the query: instead of using something similar to
    <code>
    Like [Enter Value Here]
    </code>
    use
    <code>
    Like [Forms]![NameOfTheForm]![Serial]
    </code>
    Another option is to remove the condition from the query, and pass it to the report in the WhereCondition argument of DoCmd.OpenReport:
    <code>
    stDocName = "Report-printed"
    DoCmd.OpenReport ReportName:=stDocName, WhereCondition:="[NameOfTheField] Like '" & Me.Serial & "'"
    </code>
    Substitute the relevant name.

Posting Permissions

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