473,899 Members | 3,655 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)
If I simply use
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.OpenRecordset("qryMIMATRIX")
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.OpenRecordse t() then no filtering happens.
I would like to know how I can make this work?
Mar 16 '12 #1
5 2194
32,584 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
99 New Member
Here's the query:
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM First(qryMIMATRIXSELECT!A_PLANDATE) AS [FirstOfvolgende inspectie]
  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");
Mar 17 '12 #3
32,584 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
99 New Member
Tried this:
Expand|Select|Wrap|Line Numbers
  1. Set rst = db.QueryDefs("qryMIMATRIX").OpenRecordset(dbOpenSnapshot, , dbReadOnly)
Expand|Select|Wrap|Line Numbers
  1.   Set rst = db.OpenRecordset(SQL, dbOpenSnapshot, , dbReadOnly)
Again error 3001 saying invalid object.
Mar 19 '12 #5
32,584 Recognized Expert Moderator MVP
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

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?
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
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 retreive the data for that form. I would manually set each field if the user was editing a record and I would copy each field from the form into my object when they click save. I want to develop some new forms but this time I want to try to make...
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 etc.,use "<Form name=xxxx Action=MyAction.ASP method=post>........</Form>" then these user input values will be submit to action page to run reports for user.
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 and I want some user input to go in there every time the report is run. I'm putting = into the control source but it comes up as #Name? when I run the report. If I put something in the record source for the main form, the text
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> When the user clicks the submit button on asppage.asp, it will invoke aspprocess.asp page aspprocess.asp code can get the user input from asppage.asp by doing:
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 type="button" value="Add Quote" onclick="document.getElementById('nyhed').value+=''"> The button works fine and insterts into the textarea. Although I want to make a button which onclick asks the user for a
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 works, however so does the injection methods I have used.... These are the examples of code I have tried to use to fix the problem. 1. FrmUserName=replace (FrmUserName, " ' ", "") 2. function stripQuotes(FrmUserName) stripQuotes =...
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:
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
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.