Access Set DAO Recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • m2techinc
    New Member
    • May 2007
    • 10

    Access Set DAO Recordset

    I've written a function which uses a DAO Recordset. The following statement sets the recordset:
    Set rs = db.OpenRecordse t("qryLast24Mon ths")

    My dilemma is that when my query has a criteria set as follows: [forms]![frmModels].[ModelNum], the function will not work due to a syntax error. However, if I set the criteria to an actual modelnum such as 7300, the function works just fine.

    Any help or ideas are appreciated.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Originally posted by m2techinc
    I've written a function which uses a DAO Recordset. The following statement sets the recordset:
    Set rs = db.OpenRecordse t("qryLast24Mon ths")

    My dilemma is that when my query has a criteria set as follows: [forms]![frmModels].[ModelNum], the function will not work due to a syntax error. However, if I set the criteria to an actual modelnum such as 7300, the function works just fine.

    Any help or ideas are appreciated.
    Try changing the . to a !

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by m2techinc
      I've written a function which uses a DAO Recordset. The following statement sets the recordset:
      Set rs = db.OpenRecordse t("qryLast24Mon ths")

      My dilemma is that when my query has a criteria set as follows: [forms]![frmModels].[ModelNum], the function will not work due to a syntax error. However, if I set the criteria to an actual modelnum such as 7300, the function works just fine.

      Any help or ideas are appreciated.
      This question may seem a little silly, but is frmModels Open?

      Comment

      • m2techinc
        New Member
        • May 2007
        • 10

        #4
        Originally posted by ADezii
        This question may seem a little silly, but is frmModels Open?
        The form is open...I also tried changing the . to a ! but it still throws a run-time error "Item not found in this collection".

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          That usually means you've misspelled something.

          What's db set to?

          Comment

          • m2techinc
            New Member
            • May 2007
            • 10

            #6
            Originally posted by Rabbit
            That usually means you've misspelled something.

            What's db set to?
            db is set as follows:
            Set db = CurrentDb()

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              Does the query work outside of code? What's the SQL for the query?

              Comment

              • m2techinc
                New Member
                • May 2007
                • 10

                #8
                Originally posted by Rabbit
                Does the query work outside of code? What's the SQL for the query?
                The query does work outside the code so I decided to try to put the query SQL statement in my function instead and was able to get it to work that way. Tks.

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  Originally posted by m2techinc
                  The query does work outside the code so I decided to try to put the query SQL statement in my function instead and was able to get it to work that way. Tks.
                  Well, glad you got it working. Good luck.

                  Comment

                  • JConsulting
                    Recognized Expert Contributor
                    • Apr 2007
                    • 603

                    #10
                    Originally posted by m2techinc
                    I've written a function which uses a DAO Recordset. The following statement sets the recordset:
                    Set rs = db.OpenRecordse t("qryLast24Mon ths")

                    My dilemma is that when my query has a criteria set as follows: [forms]![frmModels].[ModelNum], the function will not work due to a syntax error. However, if I set the criteria to an actual modelnum such as 7300, the function works just fine.

                    Any help or ideas are appreciated.
                    Jet's pretty strange about recordsets. Sometimes you can get away with using just the query name, others you can't. there is a workaround

                    Set rs = db.OpenRecordse t("select * from qryLast24Months ;")

                    Should do.
                    J

                    Comment

                    Working...