Results 1 to 4 of 4
  1. #1
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67

    Syntax In Query Criteria Referencing Module Code Variable

    ACCESS V.2003

    I have some code as:

    Dim d As Database
    Dim r As Recordset
    Dim strFldVal As String
    Set d = DBEngine(0)(0)

    Set r = d.OpenRecordset("select Max (RR_MONTH) from tbl_Mbr_ANOC_Data")
    r.MoveFirst
    strFldVal = Format(Nz(r.Fields(0)), "00")



    Which give the max value in tbl_Mbr_ANOC_Data in the field RR_MONTH

    I would like to reference that value as criteria in a query. Can anyone tell me what the syntax in the query criteria field would be?

    Thanks..

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    To continue to use this method, you'd have to make the variable a public one and create a function that returned its value. Then you'd call the function in the criteria. That said, the easiest solution is probably to use that query as a subquery in the criteria or (probably more efficient) join to it in your query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    orcinus is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    67
    Quote Originally Posted by pbaldy View Post
    To continue to use this method, you'd have to make the variable a public one and create a function that returned its value. Then you'd call the function in the criteria. That said, the easiest solution is probably to use that query as a subquery in the criteria or (probably more efficient) join to it in your query.
    Cool, this works..thanks!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Saving Module Code to Text Files
    By ioMatt in forum Modules
    Replies: 2
    Last Post: 07-02-2011, 08:18 AM
  2. using FindFirst with a Date Criteria (syntax error)
    By ajetrumpet in forum Programming
    Replies: 2
    Last Post: 09-10-2010, 11:01 PM
  3. Variable Table Names in a Module
    By Jessica in forum Modules
    Replies: 1
    Last Post: 04-19-2010, 07:38 PM
  4. Replies: 23
    Last Post: 03-26-2009, 06:50 PM
  5. Variable Criteria
    By JamesLens in forum Queries
    Replies: 0
    Last Post: 01-02-2009, 04:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums