OpenRecordset.

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

    OpenRecordset.

    Hi.
    Can you help me on that:
    I want to use OpenRecordset to open a query.
    Normally, the query gets some parameters from a form.
    How do I pass the same parameters to the Recordset I want to open?

    Thanks a lot


  • Wayne Morgan

    #2
    Re: OpenRecordset.

    The easiest explanation here is probably just an example.

    Dim rst As DAO.Recordset, db As DAO.Database
    Dim qdf As DAO.QueryDef, prm As DAO.Parameter
    Set db = CurrentDb
    Set qdf = db.QueryDefs("M yQuery")
    Set prm = qdf.Parameters( "[Forms]![Form1]![Textbox1]")
    prm = 21
    Set rst = qdf.OpenRecords et
    'other stuff here
    rst.Close
    Set rst = Nothing
    Set prm = Nothing
    Set qdf = Nothing
    Set db = Nothing

    If you have more than one parameter, use a different parameter variable for
    each parameter. Set each one to the name of the parameter in the query then
    set the value of each one prior to opening the recordset.

    --
    Wayne Morgan
    MS Access MVP


    "AccessUser " <shoravig@bezeq int.net> wrote in message
    news:4240150b$1 @news.bezeqint. net...[color=blue]
    > Hi.
    > Can you help me on that:
    > I want to use OpenRecordset to open a query.
    > Normally, the query gets some parameters from a form.
    > How do I pass the same parameters to the Recordset I want to open?[/color]


    Comment

    • AccessUser

      #3
      Re: OpenRecordset.

      Thanks.

      Only one question:
      What is the meaning of
      " prm = 21 "
      and what happens if there are actually more then one parameter. Do they all
      get the value of 21?


      "Wayne Morgan" <comprev_gothro ughthenewsgroup @hotmail.com> wrote in message
      news:VZU%d.1890 $yq2.585@newssv r12.news.prodig y.com...[color=blue]
      > The easiest explanation here is probably just an example.
      >
      > Dim rst As DAO.Recordset, db As DAO.Database
      > Dim qdf As DAO.QueryDef, prm As DAO.Parameter
      > Set db = CurrentDb
      > Set qdf = db.QueryDefs("M yQuery")
      > Set prm = qdf.Parameters( "[Forms]![Form1]![Textbox1]")
      > prm = 21
      > Set rst = qdf.OpenRecords et
      > 'other stuff here
      > rst.Close
      > Set rst = Nothing
      > Set prm = Nothing
      > Set qdf = Nothing
      > Set db = Nothing
      >
      > If you have more than one parameter, use a different parameter variable
      > for each parameter. Set each one to the name of the parameter in the query
      > then set the value of each one prior to opening the recordset.
      >
      > --
      > Wayne Morgan
      > MS Access MVP
      >
      >
      > "AccessUser " <shoravig@bezeq int.net> wrote in message
      > news:4240150b$1 @news.bezeqint. net...[color=green]
      >> Hi.
      >> Can you help me on that:
      >> I want to use OpenRecordset to open a query.
      >> Normally, the query gets some parameters from a form.
      >> How do I pass the same parameters to the Recordset I want to open?[/color]
      >
      >[/color]


      Comment

      • Trevor Best

        #4
        Re: OpenRecordset.

        Wayne Morgan wrote:[color=blue]
        > The easiest explanation here is probably just an example.
        >
        > Dim rst As DAO.Recordset, db As DAO.Database
        > Dim qdf As DAO.QueryDef, prm As DAO.Parameter
        > Set db = CurrentDb
        > Set qdf = db.QueryDefs("M yQuery")
        > Set prm = qdf.Parameters( "[Forms]![Form1]![Textbox1]")
        > prm = 21
        > Set rst = qdf.OpenRecords et
        > 'other stuff here
        > rst.Close
        > Set rst = Nothing
        > Set prm = Nothing
        > Set qdf = Nothing
        > Set db = Nothing
        >
        > If you have more than one parameter, use a different parameter variable for
        > each parameter. Set each one to the name of the parameter in the query then
        > set the value of each one prior to opening the recordset.
        >[/color]

        I would do it:

        for each prm in qdf.Parameters
        prm.value = Eval(prm.name)
        next

        assuming the relevant form was open.

        --
        This sig left intentionally blank

        Comment

        • Wayne Morgan

          #5
          Re: OpenRecordset.

          prm = 21 is just assigning the value of 21 to the parameter. It was just an
          example, assign the appropriate value(s) for your parameter(s). Each
          parameter will get its own value.

          --
          Wayne Morgan
          MS Access MVP


          "AccessUser " <shoravig@bezeq int.net> wrote in message
          news:4240217e@n ews.bezeqint.ne t...[color=blue]
          > Thanks.
          >
          > Only one question:
          > What is the meaning of
          > " prm = 21 "
          > and what happens if there are actually more then one parameter. Do they
          > all get the value of 21?[/color]


          Comment

          Working...