473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

recordsets

I have used recordsets in my query but only referenceing an sql string and
not a query. I tried to reference a query that was created but it falls
over.

I have that works:
dim Rst2 as DAO.Recordset
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This doesnt:
Dim Rst3 as DAO.Recordset
Set Rst3 = db.OpenRecordset("Myexistingquery")

it falls over on the last line by saying object not found.

Your help would be much appreciated.

Regards
Peter
Nov 13 '05 #1
13 1731
Peter,

You haven't defined the object variable "db". Add the following as lines 2
and 3:
Dim Db As DAO.Database
Set Db = CurrentDb()

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@newsg3.svr.pol.co.uk...
I have used recordsets in my query but only referenceing an sql string and
not a query. I tried to reference a query that was created but it falls
over.

I have that works:
dim Rst2 as DAO.Recordset
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This doesnt:
Dim Rst3 as DAO.Recordset
Set Rst3 = db.OpenRecordset("Myexistingquery")

it falls over on the last line by saying object not found.

Your help would be much appreciated.

Regards
Peter

Nov 13 '05 #2
sorry I didnt mention those they are defined as you set out below.
"PC Datasheet" <no****@nospam.spam> wrote in message
news:e7*****************@newsread3.news.atl.earthl ink.net...
Peter,

You haven't defined the object variable "db". Add the following as lines 2
and 3:
Dim Db As DAO.Database
Set Db = CurrentDb()

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@newsg3.svr.pol.co.uk...
I have used recordsets in my query but only referenceing an sql string and not a query. I tried to reference a query that was created but it falls
over.

I have that works:
dim Rst2 as DAO.Recordset
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This doesnt:
Dim Rst3 as DAO.Recordset
Set Rst3 = db.OpenRecordset("Myexistingquery")

it falls over on the last line by saying object not found.

Your help would be much appreciated.

Regards
Peter


Nov 13 '05 #3
Double Check! Do you have "DAO" in front of database? Do you have the Set Db
statement as I showed?

Steve
PC Datasheet
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news8.svr.pol.co.uk...
sorry I didnt mention those they are defined as you set out below.
"PC Datasheet" <no****@nospam.spam> wrote in message
news:e7*****************@newsread3.news.atl.earthl ink.net...
Peter,

You haven't defined the object variable "db". Add the following as lines 2
and 3:
Dim Db As DAO.Database
Set Db = CurrentDb()

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@newsg3.svr.pol.co.uk...
I have used recordsets in my query but only referenceing an sql string

and not a query. I tried to reference a query that was created but it falls over.

I have that works:
dim Rst2 as DAO.Recordset
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This doesnt:
Dim Rst3 as DAO.Recordset
Set Rst3 = db.OpenRecordset("Myexistingquery")

it falls over on the last line by saying object not found.

Your help would be much appreciated.

Regards
Peter



Nov 13 '05 #4
here it is just to clarify

Dim db As DAO.Database
Dim Rst3 As DAO.Recordset
Set db = CurrentDb

******************
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This section works
***********************
this doesnt
Set Rst3 = db.OpenRecordset("Myqueryindatabase")
the reference section has the dao reference checked.
kind regards
Peter
"PC Datasheet" <no****@nospam.spam> wrote in message
news:1u****************@newsread2.news.atl.earthli nk.net...
Double Check! Do you have "DAO" in front of database? Do you have the Set Db statement as I showed?

Steve
PC Datasheet
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news8.svr.pol.co.uk...
sorry I didnt mention those they are defined as you set out below.
"PC Datasheet" <no****@nospam.spam> wrote in message
news:e7*****************@newsread3.news.atl.earthl ink.net...
Peter,

You haven't defined the object variable "db". Add the following as
lines
2 and 3:
Dim Db As DAO.Database
Set Db = CurrentDb()

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@newsg3.svr.pol.co.uk...
> I have used recordsets in my query but only referenceing an sql
string
and
> not a query. I tried to reference a query that was created but it

falls > over.
>
> I have that works:
> dim Rst2 as DAO.Recordset
> Set Rst2 = db.OpenRecordset(StrSelectPrior)
> Rst2.MoveLast
> Me.TxtPrior.Value = Rst2.RecordCount
>
> This doesnt:
> Dim Rst3 as DAO.Recordset
> Set Rst3 = db.OpenRecordset("Myexistingquery")
>
> it falls over on the last line by saying object not found.
>
> Your help would be much appreciated.
>
> Regards
> Peter
>
>



Nov 13 '05 #5

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news5.svr.pol.co.uk...
here it is just to clarify

Dim db As DAO.Database
Dim Rst3 As DAO.Recordset
Set db = CurrentDb

******************
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This section works
***********************
this doesnt
Set Rst3 = db.OpenRecordset("Myqueryindatabase")
the reference section has the dao reference checked.
kind regards
Peter

Try Set Rst3 = db.OpenRecordset("Myqueryindatabase", dbOpenDynaset)

If you leave the second argument blank it assumes that the source is a table
which is why you're getting the error. Have a look in the VBA help file for
OpenRecordset.

Jeff
Nov 13 '05 #6
Interestingly Jeff it now give :
Object variable or With block variable not set (Error 91)

the help section wasnt very helpful on this error.

"Jeff Smith" <No***@Not.This.Address> wrote in message
news:ci**********@lust.ihug.co.nz...

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news5.svr.pol.co.uk...
here it is just to clarify

Dim db As DAO.Database
Dim Rst3 As DAO.Recordset
Set db = CurrentDb

******************
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This section works
***********************
this doesnt
Set Rst3 = db.OpenRecordset("Myqueryindatabase")
the reference section has the dao reference checked.
kind regards
Peter

Try Set Rst3 = db.OpenRecordset("Myqueryindatabase", dbOpenDynaset)

If you leave the second argument blank it assumes that the source is a

table which is why you're getting the error. Have a look in the VBA help file for OpenRecordset.

Jeff

Nov 13 '05 #7
Interestingly Jeff it now give :
Object variable or With block variable not set (Error 91)

the help section wasnt very helpful on this error.

"Jeff Smith" <No***@Not.This.Address> wrote in message
news:ci**********@lust.ihug.co.nz...

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news5.svr.pol.co.uk...
here it is just to clarify

Dim db As DAO.Database
Dim Rst3 As DAO.Recordset
Set db = CurrentDb

******************
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This section works
***********************
this doesnt
Set Rst3 = db.OpenRecordset("Myqueryindatabase")
the reference section has the dao reference checked.
kind regards
Peter

Try Set Rst3 = db.OpenRecordset("Myqueryindatabase", dbOpenDynaset)

If you leave the second argument blank it assumes that the source is a

table which is why you're getting the error. Have a look in the VBA help file for OpenRecordset.

Jeff

Nov 13 '05 #8
Interestingly Jeff it now give :
Object variable or With block variable not set (Error 91)

the help section wasnt very helpful on this error.

"Jeff Smith" <No***@Not.This.Address> wrote in message
news:ci**********@lust.ihug.co.nz...

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news5.svr.pol.co.uk...
here it is just to clarify

Dim db As DAO.Database
Dim Rst3 As DAO.Recordset
Set db = CurrentDb

******************
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This section works
***********************
this doesnt
Set Rst3 = db.OpenRecordset("Myqueryindatabase")
the reference section has the dao reference checked.
kind regards
Peter

Try Set Rst3 = db.OpenRecordset("Myqueryindatabase", dbOpenDynaset)

If you leave the second argument blank it assumes that the source is a

table which is why you're getting the error. Have a look in the VBA help file for OpenRecordset.

Jeff

Nov 13 '05 #9
Something just went wrong on my server isp end hence the three identical
posts my apologies this WAS NOT an attempt to get attention.

regards

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news6.svr.pol.co.uk...
Interestingly Jeff it now give :
Object variable or With block variable not set (Error 91)

the help section wasnt very helpful on this error.

"Jeff Smith" <No***@Not.This.Address> wrote in message
news:ci**********@lust.ihug.co.nz...

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news5.svr.pol.co.uk...
here it is just to clarify

Dim db As DAO.Database
Dim Rst3 As DAO.Recordset
Set db = CurrentDb

******************
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This section works
***********************
this doesnt
Set Rst3 = db.OpenRecordset("Myqueryindatabase")
the reference section has the dao reference checked.
kind regards
Peter

Try Set Rst3 = db.OpenRecordset("Myqueryindatabase", dbOpenDynaset)

If you leave the second argument blank it assumes that the source is a

table
which is why you're getting the error. Have a look in the VBA help file

for
OpenRecordset.

Jeff


Nov 13 '05 #10
Try this:

Set rst = CurrentDb.QueryDefs("qryInvoiceEmployee").OpenReco rdset

HTH -Linda
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@newsg3.svr.pol.co.uk...
I have used recordsets in my query but only referenceing an sql string and
not a query. I tried to reference a query that was created but it falls
over.

I have that works:
dim Rst2 as DAO.Recordset
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This doesnt:
Dim Rst3 as DAO.Recordset
Set Rst3 = db.OpenRecordset("Myexistingquery")

it falls over on the last line by saying object not found.

Your help would be much appreciated.

Regards
Peter

Nov 13 '05 #11
Couple things. Make sure the query name is spelled right and that you can open it manually. Also,
if the query is using parameters this will not work. And if it's an
Action query (INSERT INTO, UPDATE or DELETE) you will need to either use the docmd.OpenQuery or
execute via a QueryDef

Dim db as DAO.Database
Dim qdfChange As DAO.QueryDef
Set db = CurrentDb()
Set qd = db.OpenQueryDef(queryname)

qd.Execute
qd.Close

--
Reggie

----------
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@newsg3.svr.pol.co.uk...
Something just went wrong on my server isp end hence the three identical
posts my apologies this WAS NOT an attempt to get attention.

regards

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news6.svr.pol.co.uk...
Interestingly Jeff it now give :
Object variable or With block variable not set (Error 91)

the help section wasnt very helpful on this error.

"Jeff Smith" <No***@Not.This.Address> wrote in message
news:ci**********@lust.ihug.co.nz...
>
> "Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
> news:ci**********@news5.svr.pol.co.uk...
> > here it is just to clarify
> >
> > Dim db As DAO.Database
> > Dim Rst3 As DAO.Recordset
> > Set db = CurrentDb
> >
> > ******************
> > Set Rst2 = db.OpenRecordset(StrSelectPrior)
> > Rst2.MoveLast
> > Me.TxtPrior.Value = Rst2.RecordCount
> >
> > This section works
> > ***********************
> > this doesnt
> > Set Rst3 = db.OpenRecordset("Myqueryindatabase")
> >
> >
> > the reference section has the dao reference checked.
> >
> >
> > kind regards
> > Peter
>
>
> Try Set Rst3 = db.OpenRecordset("Myqueryindatabase", dbOpenDynaset)
>
> If you leave the second argument blank it assumes that the source is a

table
> which is why you're getting the error. Have a look in the VBA help file

for
> OpenRecordset.
>
> Jeff
>
>



Nov 13 '05 #12
Thanks guys Linda solution worked perfectly. Iam finding it difficult not to
write the vba but find the help for things like this any pointers?

regards
Peter
"Squirrel" <wi*****@covad.net> wrote in message
news:88**************************@msgid.meganewsse rvers.com...
Try this:

Set rst = CurrentDb.QueryDefs("qryInvoiceEmployee").OpenReco rdset

HTH -Linda
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@newsg3.svr.pol.co.uk...
I have used recordsets in my query but only referenceing an sql string and not a query. I tried to reference a query that was created but it falls
over.

I have that works:
dim Rst2 as DAO.Recordset
Set Rst2 = db.OpenRecordset(StrSelectPrior)
Rst2.MoveLast
Me.TxtPrior.Value = Rst2.RecordCount

This doesnt:
Dim Rst3 as DAO.Recordset
Set Rst3 = db.OpenRecordset("Myexistingquery")

it falls over on the last line by saying object not found.

Your help would be much appreciated.

Regards
Peter


Nov 13 '05 #13
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news8.svr.pol.co.uk...
Thanks guys Linda solution worked perfectly. Iam finding it difficult not to
write the vba but find the help for things like this any pointers?


The fact that your previous statement (correct BTW) gave the error it did and
that Linda's suggestion worked indicates that your database variable (db) had
gone out of scope and was no longer pointing at a database object.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marco Alting | last post by:
Is it possible to INNER JOIN two recordsets in ASP? I don't mean the normal JOIN you would use with two tables, but actually join the recordsets in ASP?
2
by: Steve Marciniak | last post by:
I'm trying to display different recordsets (which are 1 field each) as columns right next to one another. For example, Recordset1 is displayed on the left hand side of the screen. Recordset2 is...
6
by: Steve Jorgensen | last post by:
I keep having problems in which ADO disconnected recordset work under some circumstances, but lose all their data at other times, having no rows or fields, though the recordset object still exists....
2
by: Pieter Linden | last post by:
The answer to this one is probably "test it yourself and find out!", but I'll ask anyway. Pursuant to my previous question - sending separate recordsets to Word using the CreateTableFromRecordset...
1
by: lakshmi | last post by:
Hi all, I recently rewrote a data intensive C++ program in C#. The C++ program was traversing 3 recordsets that were all open at the same time. I replaced those 3 recordsets with 3 .NET data...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
24
by: Donald Grove | last post by:
I want to populate an array with values from an ado recordset (multiple rows) I use the absolute position of the cursor in the recordset to define the row of my array to be populated. I have a...
4
by: mrmagoo | last post by:
I'm building a vb.net Forms project that is getting data from a SQL Server database. One of the main goals of the project is to be really responsive to events, such as textbox change events. I...
4
by: rdemyan via AccessMonster.com | last post by:
Can someone help me with creating code that will look for DAO recordsets in modules and then check to see if the recordset is also closed in the module. All of my recordsets are of the form rs*...
11
by: BeckR | last post by:
Hello - Thanks for reading my post. I am a newbie when it comes to VBA programming, but have managed to do what I need to do, until now. I have an Access 2000 database (running WinXP Pro...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.