473,508 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem Opening Query in VBA

99 New Member
I need to filter a form using the selection made by user from a dropdown.I have used the following code which throws an error: invalid argument
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboLocate_AfterUpdate()
  2. Dim rst As DAO.Recordset, db As Database
  3. Dim strCriteria, SQL As String
  4.    strCriteria = "[A_LOCATION]=" & cboLocate
  5.    Set rst = Me.RecordsetClone
  6.    'rst.FindFirst (strCriteria = "[A_LOCATE]=" & cboLocate)
  7.    Set db = CurrentDb
  8.    Set rst = db.OpenRecordset("qryMIMATRIX", dbOpenDynaset, dbReadOnly, dbOptimistic)
  9.       If rst.NoMatch Then
  10.       MsgBox "No entry found"
  11.    Else
  12.       Me.FilterOn = False
  13.     Me.Filter = strCriteria
  14.     Me.FilterOn = True
  15.    End If
  16. End Sub
The error points to the code:
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.OpenRecordset("qryMIMATRIX", dbOpenDynaset, dbReadOnly, dbOptimistic)
  2.  
If I simply use
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.OpenRecordset("qryMIMATRIX")
  2.  
I am asked to enter a parameter value.

qryMIMATRIX is a query.I also tried using
Expand|Select|Wrap|Line Numbers
  1. Sql="select * from qryMIMATRIX"
  2. Set rst=db.OpenRecordset(SQL)
If I do not use db.OpenRecordset() then no filtering happens.
I would like to know how I can make this work?
Mar 16 '12 #1
5 2181
NeoPa
32,557 Recognized Expert Moderator MVP
Line #8 appears perfectly correct as far as I can see. It may well be easier to use the other format to open a query (Below), but your VBA here seems fine.
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.QueryDefs("qryMIMATRIX").OpenRecordset(Type:=, Options:=, LockEdit:=)
As your VBA seems ok, I would look at the query itself and see if that runs when opened normally.
Mar 16 '12 #2
HiGu
99 New Member
Here's the query:
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM First(qryMIMATRIXSELECT!A_PLANDATE) AS [FirstOfvolgende inspectie]
  2. SELECT qryMIMATRIXSELECT.A_ID, qryMIMATRIXSELECT.A_PLANDATE, qryMIMATRIXSELECT.A_LOCATION, qryMIMATRIXSELECT.A_JOBNO, IIf(IsNull(qryMIMATRIXSELECT!A_PROJECTID),qryMIMATRIXSELECT!A_EQUIPDESCR,"**13M** " & qryMIMATRIXSELECT!A_EQUIPDESCR) AS exprA_EQUIPDESCR, qryMIMATRIXSELECT.A_NENGROUP, qryMIMATRIXSELECT.A_PRIORITY, qryMIMATRIXSELECT.A_MENO, qryMIMATRIXSELECT.A_DAYO
  3. FROM qryMIMATRIXSELECT
  4. GROUP BY qryMIMATRIXSELECT.A_ID, qryMIMATRIXSELECT.A_PLANDATE, qryMIMATRIXSELECT.A_LOCATION, qryMIMATRIXSELECT.A_JOBNO, IIf(IsNull(qryMIMATRIXSELECT!A_PROJECTID),qryMIMATRIXSELECT!A_EQUIPDESCR,"**13M** " & qryMIMATRIXSELECT!A_EQUIPDESCR), qryMIMATRIXSELECT.A_NENGROUP, qryMIMATRIXSELECT.A_PRIORITY, qryMIMATRIXSELECT.A_MENO, qryMIMATRIXSELECT.A_DAYO
  5. ORDER BY qryMIMATRIXSELECT.A_PLANDATE
  6. PIVOT qryMIMATRIXSELECT.periodes In ("0","2","4","6","8","10","12","14","16","18","20","22","24","26","28","30","32","34","36","38","40","42","44","46","48","50","52");
  7.  
Mar 17 '12 #3
NeoPa
32,557 Recognized Expert Moderator MVP
I'm confused. Why would you post the SQL of the query? I can't test it for you (nor would I if I could - That's your responsibility).

I've already checked the VBA and I see nothing wrong with it. The fact that the query is a Cross-Tab is important information that would have been a good idea to include in the question, but doesn't change the understanding that the problem is with the query.

Actually, one thought occurs to me :
Although I'm pretty sure Help has nothing to say on the matter, the parameters dbReadOnly and dbOptimistic certainly make little sense together. They may be disallowed without this being documented so I would try passing parameters that make sense. Try leaving the Options parameter unset and use dbReadOnly for LockEdit instead. Also, if it's read/only, why are you using a Dynaset instead of a SnapShot?
Mar 17 '12 #4
HiGu
99 New Member
Tried this:
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.QueryDefs("qryMIMATRIX").OpenRecordset(dbOpenSnapshot, , dbReadOnly)
  2.  
and
Expand|Select|Wrap|Line Numbers
  1.   Set rst = db.OpenRecordset(SQL, dbOpenSnapshot, , dbReadOnly)
Again error 3001 saying invalid object.
Mar 19 '12 #5
NeoPa
32,557 Recognized Expert Moderator MVP
NeoPa:
As your VBA seems ok, I would look at the query itself and see if that runs when opened normally.
It doesn't seem to be a VBA problem then.

What did you find when you tested the query manually as suggested in post #2?
Mar 19 '12 #6

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

Similar topics

2
3061
by: reneeccwest | last post by:
Different user input boxes are automatically populated based on a value of the dropdown box. Can anyone help me on that?
3
8515
by: reneeccwest | last post by:
how can I make the value of the user input box as a desired color? (such as red) Is it also possible to change the color in the user input box background? RC
0
1977
by: Ray Lavelle | last post by:
I'm new to VB .NET. In the past when creating an application, if I had an input form I would just call the set and get methods on the object that mapped to my database table in order to store and...
0
1561
by: Michael | last post by:
Hi All, I am working on my intranet reporting web site, by use of IIS5 + Office2000 +SQL2000. Currently, the first step, I show user an ASP web-interface to collect user input, keyword...
3
16902
by: Clare | last post by:
Hi I have a report that is made of 4 subreports. There is no actual information in the main report, and the record source is empty. In the Header section of the main report, I have a text box...
2
2102
by: Matthew Louden | last post by:
In ASP, if I have asppage.asp for GUI and aspprocess.asp for process requests from database. In asppage.asp code will be like: <form action="aspprocess.asp" method="POST"> GUI CODE </form> ...
2
9645
by: danielboendergaard | last post by:
Hey Im making a homepage in php. I use a html form to put data into mysql and i want to make some buttons which inserts user input values into a textarea. I have used a button like this: <input...
4
2306
by: joesin | last post by:
I recently found a vulnerability on my website that allowed sql injection. I have been trying to write some code that would clean user data but have been running into problems. The validation still...
29
2505
parshupooja
by: parshupooja | last post by:
Hi, I am working in Asp.Net 2.0, SQL Server, C#. I am trying to create a User Input form which has lots of fields such as : salutation; Firstname: lastname: address: Zip: Phone:
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7331
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,...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.