Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2002
    Posts
    192

    Unanswered: Opening a parameter query in Code

    How does one open a parameter in code?

    Say the query is

    SELECT * FROM tblTest WHERE TestID = [Enter an ID];

    The answer needs to be in Access 97 DAO. NOT ADO.

    Here is my code that opens a non parameter query.

    dim dbs as database
    dim rstTest as recordset
    dim strTest as string

    strTest = "SELECT * FROM qryTest;"
    Set dbs = CurrentDB
    Set rstTest = dbs.OpenRecordset(strTest, DbOpenSnapshot)
    rstTest.close
    dbs.close

  2. #2
    Join Date
    Nov 2002
    Posts
    150

    Re: Opening a parameter query in Code

    Create a reference to the query and then play with it:

    Public Function Test()
    Dim rs As Recordset
    Dim qdf As QueryDef
    Set qdf = CurrentDb.QueryDefs("Query1")
    qdf.Parameters(0) = 2
    Set rs = qdf.OpenRecordset
    If Not rs.EOF Then
    MsgBox rs(0)
    End If
    End Function

  3. #3
    Join Date
    Mar 2002
    Posts
    192
    It works great. much thanks.

  4. #4
    Join Date
    Nov 2002
    Posts
    150
    Glad I could help.....

Posting Permissions

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