By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,361 Members | 1,352 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,361 IT Pros & Developers. It's quick & easy.

Access Set DAO Recordset

P: 10
I've written a function which uses a DAO Recordset. The following statement sets the recordset:
Set rs = db.OpenRecordset("qryLast24Months")

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.
May 31 '07 #1
Share this Question
Share on Google+
9 Replies

Rabbit
Expert Mod 10K+
P: 12,441
I've written a function which uses a DAO Recordset. The following statement sets the recordset:
Set rs = db.OpenRecordset("qryLast24Months")

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 !
May 31 '07 #2

ADezii
Expert 5K+
P: 8,750
I've written a function which uses a DAO Recordset. The following statement sets the recordset:
Set rs = db.OpenRecordset("qryLast24Months")

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?
May 31 '07 #3

P: 10
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".
Jun 1 '07 #4

Rabbit
Expert Mod 10K+
P: 12,441
That usually means you've misspelled something.

What's db set to?
Jun 1 '07 #5

P: 10
That usually means you've misspelled something.

What's db set to?
db is set as follows:
Set db = CurrentDb()
Jun 1 '07 #6

Rabbit
Expert Mod 10K+
P: 12,441
Does the query work outside of code? What's the SQL for the query?
Jun 1 '07 #7

P: 10
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.
Jun 1 '07 #8

Rabbit
Expert Mod 10K+
P: 12,441
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.
Jun 1 '07 #9

JConsulting
Expert 100+
P: 603
I've written a function which uses a DAO Recordset. The following statement sets the recordset:
Set rs = db.OpenRecordset("qryLast24Months")

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.OpenRecordset("select * from qryLast24Months;")

Should do.
J
Jun 3 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.