Refrence a query in VB

T

TC114

I am trying to reference specific fields in a saved query. I can not seem to
figure it out do I have to just create the query in VB

' to open the query
DoCmd.OpenQuery "qryforrpt", acViewNormal, acReadOnly

'Where I am trying to reference the query
If (IsNull(Query![qryforrpt]![LockPawlAssembly])) = False Then
objWord.ActiveDocument.Bookmarks("R1C1").Range.Text = ""

I have coming back to this for a few days and can not figure it out.

Any help will be greatly appreciated.
Thanks
Tim
 
A

Amy Blankenship

TC114 said:
I am trying to reference specific fields in a saved query. I can not seem
to
figure it out do I have to just create the query in VB

' to open the query
DoCmd.OpenQuery "qryforrpt", acViewNormal, acReadOnly

'Where I am trying to reference the query
If (IsNull(Query![qryforrpt]![LockPawlAssembly])) = False Then
objWord.ActiveDocument.Bookmarks("R1C1").Range.Text = ""

I have coming back to this for a few days and can not figure it out.

This may help you:

http://www.mvps.org/access/queries/qry0003.htm

Once you have the recordset, you should be able to use a for next loop to
look at the results or use FindFirst, etc., depending on what you are
looking to do.
 
T

TC114

Amy,
That helped but I am still getting an error. Here is my code

Dim db As Database
Dim rst As Recordset
Dim qdfParmQry As QueryDef
Set db = CurrentDb()
Set qdfParmQry = db.QueryDefs("qryforrpt")

'On this line I am getting the error "Item not found in this collection"
If (IsNull(qdfParmQry![LockPawlAssembly])) = False Then
Any ideas.
Thank you for your help
Tim


Amy said:
I am trying to reference specific fields in a saved query. I can not seem
to
[quoted text clipped - 8 lines]
I have coming back to this for a few days and can not figure it out.

This may help you:

http://www.mvps.org/access/queries/qry0003.htm

Once you have the recordset, you should be able to use a for next loop to
look at the results or use FindFirst, etc., depending on what you are
looking to do.
 
T

TC114

Amy
Just wanted to thank you, I was using a parameter query so I had to use a
little bit different code.
http://www.mvps.org/access/queries/qry0013.htm

Tim
Amy,
That helped but I am still getting an error. Here is my code

Dim db As Database
Dim rst As Recordset
Dim qdfParmQry As QueryDef
Set db = CurrentDb()
Set qdfParmQry = db.QueryDefs("qryforrpt")

'On this line I am getting the error "Item not found in this collection"
If (IsNull(qdfParmQry![LockPawlAssembly])) = False Then
Any ideas.
Thank you for your help
Tim
[quoted text clipped - 9 lines]
look at the results or use FindFirst, etc., depending on what you are
looking to do.
 
A

Amy Blankenship

TC114 said:
Amy,
That helped but I am still getting an error. Here is my code

Dim db As Database
Dim rst As Recordset
Dim qdfParmQry As QueryDef
Set db = CurrentDb()
Set qdfParmQry = db.QueryDefs("qryforrpt")

'On this line I am getting the error "Item not found in this collection"
If (IsNull(qdfParmQry![LockPawlAssembly])) = False Then

Try

If Not IsNull(qdfParamQry("LockPawlAssembly"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top