473,568 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

open Query from Code : Getting Error

Hi,

I have looked at the example called "Open Parameter queries from code"
from the site http://www.mvps.org/access/queries/qry0003.htm

I made up a test which I though looked pretty close (which I will
paste below)

I have put it on the BeforeUpdate event of a form I am using, but
whenever it is called, I get "Run-time error '13':, Type mismatch
Could anybody give me a suggestion of what I did wrong? Probably a
typo, but I really can't spot it :(
Cheers

Max.

Private Sub Form_BeforeUpda te(Cancel As Integer)
' This is a function which will NOT ALLOW data to be entered if it has
conflicting values
' We have a query which is designed to see if to date/times and a room
passed to it would
' conflict with any of the current bookings. If it does, then it has
to NOT allow this
' entry to be entered into the database. A nice message with as much
information as possible
' should be returned... it "This entry for Room ###xx would conflict
with the booking of XXX"
Dim dbs As Database ' The Current Database
Dim rs As Recordset ' Where the query results will be held
Dim qdQry As QueryDef ' The query which will return the conflicts

Set dbs = CurrentDb()
Set qdQry = dbs.QueryDefs(" QryTemp")
' MsgBox ("aborts after this statement")
Set rs = qdQry.OpenRecor dset() ' Have rs recieve the query
results

MsgBox ("Before Update test message")
End Sub
Nov 12 '05 #1
4 11355
TC
The example is for parameter queries. You have not set any parameters! So if
QryTemp is a parameter query, "pretty close" will not be close enough.

Post the SQL text of your query, and clarify exactly what line of code the
error occurred on. Forget all the comments & stuff, they won't help us find
the problem :-)

HTH,
TC
"Max Harvey" <go****@DELTAL. org> wrote in message
news:7a******** *************** ***@posting.goo gle.com...
Hi,

I have looked at the example called "Open Parameter queries from code"
from the site http://www.mvps.org/access/queries/qry0003.htm

I made up a test which I though looked pretty close (which I will
paste below)

I have put it on the BeforeUpdate event of a form I am using, but
whenever it is called, I get "Run-time error '13':, Type mismatch
Could anybody give me a suggestion of what I did wrong? Probably a
typo, but I really can't spot it :(
Cheers

Max.

Private Sub Form_BeforeUpda te(Cancel As Integer)
' This is a function which will NOT ALLOW data to be entered if it has
conflicting values
' We have a query which is designed to see if to date/times and a room
passed to it would
' conflict with any of the current bookings. If it does, then it has
to NOT allow this
' entry to be entered into the database. A nice message with as much
information as possible
' should be returned... it "This entry for Room ###xx would conflict
with the booking of XXX"
Dim dbs As Database ' The Current Database
Dim rs As Recordset ' Where the query results will be held
Dim qdQry As QueryDef ' The query which will return the conflicts

Set dbs = CurrentDb()
Set qdQry = dbs.QueryDefs(" QryTemp")
' MsgBox ("aborts after this statement")
Set rs = qdQry.OpenRecor dset() ' Have rs recieve the query
results

MsgBox ("Before Update test message")
End Sub

Nov 12 '05 #2
"TC" <a@b.c.d> wrote in message news:<106964679 5.823362@teutho s>...
The example is for parameter queries. You have not set any parameters! So if
QryTemp is a parameter query, "pretty close" will not be close enough.

Post the SQL text of your query, and clarify exactly what line of code the
error occurred on. Forget all the comments & stuff, they won't help us find
the problem :-)

OK, I have ditched my attempt, and tried the one pretty much straight
from the web page..
Now I have a query called QryTemp,
its code is as follows

-----

SELECT tblBooking.Book ingID, tblBooking.Room ID, tblBooking.Clie ntID
FROM tblBooking
WHERE (((tblBooking.B ookingID)=[Please Enter Code:]));

-----

As for the code I am using (comments removed)

-----

Private Sub Form_BeforeUpda te(Cancel As Integer)

Dim db As Database 'current database
Dim rs As Recordset 'holds query resultset
Dim qdfParmQry As QueryDef 'the actual query object
Set db = CurrentDb()
Set qdfParmQry = db.QueryDefs("Q ryTemp")
qdfParmQry("Ple ase Enter Code:") = 3
Set rs = qdfParmQry.Open Recordset()

End Sub

-----

And I even checked to ensure that BookingID = 3 is a valid record, and
displays a result when the query is run by itself :)

As for where it crashes, it crashes on the "Set rs =
qdfParmQry.Open Recordset()" line (Thats the line highlighted in Yellow
when I go to debug, with "Run-time error '13': Type mismatch
Any assistance would be great.

NB:. This may be of importance... while in the code editor[1], I had
to go to Tools-->References and select "Microsoft DAO 3.6 Object
Library" for it to even reconise "database" as a type. Is it possible
there are more references I need to select which aren't currently
selected[2]?

[1] About reports as... Microsoft Visual Basic 6.3 Version 9108 VBA:
Retail 6.3.8863 Forms3: 2.01
[2] Currently selected referecnes are
- Visual Basic For Application
- Microsoft Access 10.0 Object Library
- Microsoft ActiveX Data Objects 2.1 Library
- OLE Automation
- Microsoft DAO 3.6 Object Library
Thnaks for any help
Max.
Nov 12 '05 #3
TC
Ok. Try changing:
Dim db As Database
Dim rs As Recordset
Dim qdfParmQry As QueryDef
to:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdfParmQry As DAO.QueryDef
Also, I'm not sure whether the Parameters collection is the default
collection of a querydef object, so also change:

qdfParmQry("Ple ase Enter Code:") = 3

to:

qdfParmQry.Para meters("Please Enter Code:") = 3

HTH,
TC

"Max Harvey" <go****@DELTAL. org> wrote in message
news:7a******** *************** ***@posting.goo gle.com... "TC" <a@b.c.d> wrote in message news:<106964679 5.823362@teutho s>...
The example is for parameter queries. You have not set any parameters! So if QryTemp is a parameter query, "pretty close" will not be close enough.

Post the SQL text of your query, and clarify exactly what line of code the error occurred on. Forget all the comments & stuff, they won't help us find the problem :-)

OK, I have ditched my attempt, and tried the one pretty much straight
from the web page..
Now I have a query called QryTemp,
its code is as follows

-----

SELECT tblBooking.Book ingID, tblBooking.Room ID, tblBooking.Clie ntID
FROM tblBooking
WHERE (((tblBooking.B ookingID)=[Please Enter Code:]));

-----

As for the code I am using (comments removed)

-----

Private Sub Form_BeforeUpda te(Cancel As Integer)

Dim db As Database 'current database
Dim rs As Recordset 'holds query resultset
Dim qdfParmQry As QueryDef 'the actual query object
Set db = CurrentDb()
Set qdfParmQry = db.QueryDefs("Q ryTemp")
qdfParmQry("Ple ase Enter Code:") = 3
Set rs = qdfParmQry.Open Recordset()

End Sub

-----

And I even checked to ensure that BookingID = 3 is a valid record, and
displays a result when the query is run by itself :)

As for where it crashes, it crashes on the "Set rs =
qdfParmQry.Open Recordset()" line (Thats the line highlighted in Yellow
when I go to debug, with "Run-time error '13': Type mismatch
Any assistance would be great.

NB:. This may be of importance... while in the code editor[1], I had
to go to Tools-->References and select "Microsoft DAO 3.6 Object
Library" for it to even reconise "database" as a type. Is it possible
there are more references I need to select which aren't currently
selected[2]?

[1] About reports as... Microsoft Visual Basic 6.3 Version 9108 VBA:
Retail 6.3.8863 Forms3: 2.01
[2] Currently selected referecnes are
- Visual Basic For Application
- Microsoft Access 10.0 Object Library
- Microsoft ActiveX Data Objects 2.1 Library
- OLE Automation
- Microsoft DAO 3.6 Object Library
Thnaks for any help
Max.

Nov 12 '05 #4
"TC" <a@b.c.d> wrote in message news:<106981808 8.506719@teutho s>...
Ok. Try changing:
Dim db As Database
Dim rs As Recordset
Dim qdfParmQry As QueryDef


to:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdfParmQry As DAO.QueryDef


Also, I'm not sure whether the Parameters collection is the default
collection of a querydef object, so also change:

qdfParmQry("Ple ase Enter Code:") = 3

to:

qdfParmQry.Para meters("Please Enter Code:") = 3

HTH,
TC

Thanks TC, everybody,

With the above correctoins I have managed to make it work. :)

I was so glad when I found the web site with the instructions, and
when they didn't work, I thought I was doomed... you guys Rock.

All the best.

Max.
Nov 12 '05 #5

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

Similar topics

2
6716
by: Colleyville Alan | last post by:
I ran into problems in an app in which I received a msg of "cannot lock the table, it is in use by another user". It turns out that I had opened a recordset with a command like set rstmyrecs = openrecordset("Tablename") to get a record count and I was trying to run a query to modify the table even though I had not yet closed the recorset. ...
5
10582
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
0
1382
by: dd_bdlm | last post by:
I have recently updated my database to include a postcode recognition function. And to perform calculations based on that recognised value. The query that makes all these calculations is very large and takes a good while to run (up to a minute?). (But I need all this data in one query so it can be reported in one report.). My problem now is I...
15
8265
by: Rob Nicholson | last post by:
I'm starting to worry a bit now. We're getting the above error when two users hit the same database/page on an ASP.NET application using ADO.NET, talking to a SQL 7 server. The error is perfectly repeatable :-( But this should help! The error is occurring inside ExecuteReader which uses a DataReader internally. Here are some things that...
3
1890
by: Joanne | last post by:
I have searched through previous threads regarding this error. I went back through all my code to make sure I closed and set to nothing all open db's and rs's. However, I still have one computer getting this error. This problem does not occur with any other users - some of whom use the database continuously. The user logs in, then goes...
10
6091
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the code below which when executed generates the following error message: 'There is already an open datareader with this command which must be closed...
10
5545
by: bluray | last post by:
Hello guys, thanks again for taking the time to help me out with my problems! This problem seems super simple in my head, however getting the coding to make it work is turing out to be not so simple... Basically what I am trying to do is have a Command Button check to see whether the current "Record ID" exists in the sister table before...
2
7161
n8kindt
by: n8kindt | last post by:
i'm stuck. i'm using access 2007 on a windows vista machine (i've tried running on xp too, though--same result) and this is the error i keep getting whenever i try running my main query: Cannot open any more databases. (Error 3048) You have reached the limit on the number of databases that can be opened at one time. Close one or more...
14
3816
by: sarabonn | last post by:
hallo Iam trying to insert a row into a access database using visual c# and iam getting an error " cannot open the action query". here is my code private void button1_Click(object sender, EventArgs e) { txt1 = textBox1.Text; txt2 = textBox2.Text;
0
7604
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...
1
7660
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...
0
7962
tracyyun
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...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
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
1
1207
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.