473,386 Members | 1,766 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,386 software developers and data experts.

queryDef Parameters and recordset, storing to variable

Hello Everyone, I am trying to read from a stored query in MS Access to a variable.

My error: Run-time error '91': Object variable or With block variable not set.

My code:

Expand|Select|Wrap|Line Numbers
  1. ######## CODE START ###########
  2.  
  3. Dim rst As DAO.Recordset
  4. Dim dbs As DAO.Database
  5. Dim qdf As DAO.QueryDef
  6.  
  7. Dim strResult As String
  8.  
  9. Set qdf = dbs.QueryDefs("Report Query")
  10.  
  11. qdf.Parameters("[Forms]![qryFormReporting]![Date_Start]") = Date_Start
  12. qdf.Parameters("[Forms]![qryFormReporting]![Date_End]") = Date_End
  13. qdf.Parameters("[Forms]![qryFormReporting]![prod_ID]") = Prod_ID
  14. qdf.Parameters("[Forms]![qryFormReporting]![class_ID]") = class_ID
  15. qdf.Parameters("[Forms]![qryFormReporting]![origin_ID]") = origin_ID
  16. qdf.Parameters("[Forms]![qryFormReporting]![Item_Type]") = Item_Type
  17. qdf.Parameters("[Forms]![qryFormReporting]![type_ID]") = type_ID
  18.  
  19. Set dbs = CurrentDb
  20. sSql = "SELECT [Participation Query].*, Items_Book_HardBack_CountSold_byDate.totHard, Items_Book_SoftBack_CountSold_byDate.totSoft, Items_Book_PaperBack_Free_CountSold_byDate.*, Items_Book_PaperBack_CountSold_byDate.totPaper, Items_Book_HardBack_CountSold_byDate.[$HB], Items_Book_SoftBack_CountSold_byDate.[$SB], Items_Book_PaperBack_CountSold_byDate.[$PB], [$HB]+[$SB]+[$PB] AS sumReport, Order_Product_Revenue_Count_by_Date.sumRevenue FROM Order_Product_Revenue_Count_by_Date, Items_Book_HardBack_CountSold_byDate, Items_Book_SoftBack_CountSold_byDate, Items_Book_PaperBack_CountSold_byDate, Items_Book_PaperBack_Free_CountSold_byDate, [Participation Query];"
  21. Set rst = qdf.OpenRecordset(sSql)
  22.  
  23. With rst
  24.     .MoveFirst
  25.     strResult = .Fields(0)
  26. End With
  27.  
  28. Set rst = Nothing
  29. Set dbs = Nothing
  30. Set qdf = Nothing
  31.  
  32. txtReport = strResult
  33.  
  34. ######## END CODE ###########
What am I missing?

Thank you so much for your help!
Jun 12 '12 #1
1 3602
Stewart Ross
2,545 Expert Mod 2GB
What you are trying to achieve is unclear. In lines 9 to 17 You have a parameterised querydef object, qdf, based on query "report query". At line 21 you try to open a separate recordset based on a SQL query, using the same qdf object - which makes no sense.

The qdf.OpenRecordset method does not take a string parameter - if you lookup the help you will find that its optional parameters relate to the type of the recordset you want to open. You don't need to supply an SQL string to a querydef's OpenRecordset method as the querydef is tied to a specific query already ("report query" in your case).

I would suggest that line 21 should actually be

Expand|Select|Wrap|Line Numbers
  1. set rs = CurrentDb.OpenRecordset(sSql)
However, I cannot see that the sql-based recordset relates at all to the parameterised querydef you are initially setting up.

It always helps if you tell us which line the error is occurring on.

-Stewart
Jun 13 '12 #2

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

Similar topics

7
by: Snyke | last post by:
Well my problem is simple: I have a class which has a variable number of members. Lets say I have a class Family and a variable number of FamilyMembers. Until now I used a member of Family called...
3
by: Mark Bergman | last post by:
We have inherited a script which runs rsh (remote shell), taking parameters from a variable, and if attempting to run a multi-word command remotely, we get an error! See the example below which...
4
by: matevz bradac | last post by:
Hi, I'm trying to implement delayed function execution, similar to OpenGL's display lists. It looks something like this: beginList (); fcn1 (); fcn2 ();
14
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I...
5
by: - Steve - | last post by:
I have a website that uses forms based authentication. In the logon.aspx page a user enters a username and password. It is then authenticated against Active Directory. After that point on any...
2
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j);...
3
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j);...
10
by: John Salerno | last post by:
If I want to have a list like this: where the first part of each tuple is a variable name and the second part is a label for the user to see, such as a form like this: First Name: ________...
19
by: phytorion | last post by:
My problem is that my code doesn't seem to be passing the parameter values to the query. I'm not very profiencient in access so i'm not sure where its going wrong. On Error GoTo...
1
by: christianlott1 | last post by:
Neither of these work. Why? -------------------------- example 1: StrQryDef = "SELECT zqUsageMailOutList.TG_CNTRCT_ID " _ & "FROM zqUsageMailOutList " _ & "WHERE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.