Query current record

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Israel

    #1

    Query current record

    I am new to Access. I have a form with a single record. The keyed field is
    PropID (number). I want to run a query from the form that will have the
    current value of PropID be the variable in the criteria of the query. The
    intent being the query returns the values of the current record of the form
    for a report. So, I want to code a pushbutton to run that query with the
    current keyed field value as the criteria and then open a report based on
    that query. How do I do this in Access. I can do this in other desktop
    RDBM programs.


  • Bob Quintal

    #2
    Re: Query current record

    "Michael Israel" <mbi24@spamless optonline.net> wrote in
    news:ogMuc.3400 3$DC1.6568282@n ews4.srv.hcvlny .cv.net:
    [color=blue]
    > I am new to Access. I have a form with a single record. The
    > keyed field is PropID (number). I want to run a query from
    > the form that will have the current value of PropID be the
    > variable in the criteria of the query. The intent being the
    > query returns the values of the current record of the form
    > for a report. So, I want to code a pushbutton to run that
    > query with the current keyed field value as the criteria and
    > then open a report based on that query. How do I do this in
    > Access. I can do this in other desktop RDBM programs.[/color]

    Rather than put the query criteria in the recordsource of the
    report, you can call the Docmd.openrepor t method with an optional
    WHERE clause that filters the report recordsource.

    So in the report calling code, first set up your criteria, then
    pass that asa follows

    Private sub CmdReportPvw_On Click ()
    Dim stReportname as string
    Dim stwhereclause as string

    streportname = "MyReport"
    stwhereclause = "PropID = " & me.PropID ' For numeric ID
    stwhereclause = "PropID = " & chr(34)& me.PropID & me.chr(34) '
    For characeter ID

    DoCmd.OpenRepor t streportname, , ,stwhereclause

    End sub.


    Bob Quintal

    Comment

    Working...