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

Error on QueryDef on Close

Hi -
All is fine if I open my form, do something, then close it.

However, if I just open it, then press the Close button (or go into
design view), I get
"object variable or with Block variable not set" error 91 on
mqdf.Close

The following code appears at the top of the module: (someone wrote it
for me)
Private mdb As DAO.Database
Private mqdf As DAO.QueryDef
Private mstrSQL As String

And when I "use" the form (don't just open and close), I execute:
'SQL to append the new record
mstrSQL = "INSERT INTO trelAdDept ( AdKey, DeptNum ) " _
& "VALUES (" & lngAdKey & ", " & lngDeptKey & ")"

'Create a temporary querydef object based on the above SQL stmt
Set mqdf = mdb.CreateQueryDef("", mstrSQL)

'Execute the querydef
mqdf.Execute dbFailOnError

It seems, though, that if I haven't executed the above code, I get the
error when I just try to close the form.

Thanks for the help! I couldn't find this in any prior postings.
sara

Apr 14 '06 #1
4 3061
I notice that you haven't set mdb to point to anything. It's a database
type, but it doesn't point to any particular database until you say
something like:
set mdb= currentdb
I think this will help with your error. But you don't have to bother with
querydefs at all- you can just say:
mdb.execute mstrSQL, dbfailonerror

hope this helps
-John

"sara" <sa*******@yahoo.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi -
All is fine if I open my form, do something, then close it.

However, if I just open it, then press the Close button (or go into
design view), I get
"object variable or with Block variable not set" error 91 on
mqdf.Close

The following code appears at the top of the module: (someone wrote it
for me)
Private mdb As DAO.Database
Private mqdf As DAO.QueryDef
Private mstrSQL As String

And when I "use" the form (don't just open and close), I execute:
'SQL to append the new record
mstrSQL = "INSERT INTO trelAdDept ( AdKey, DeptNum ) " _
& "VALUES (" & lngAdKey & ", " & lngDeptKey & ")"

'Create a temporary querydef object based on the above SQL stmt
Set mqdf = mdb.CreateQueryDef("", mstrSQL)

'Execute the querydef
mqdf.Execute dbFailOnError

It seems, though, that if I haven't executed the above code, I get the
error when I just try to close the form.

Thanks for the help! I couldn't find this in any prior postings.
sara

Apr 14 '06 #2
sounds picky of me, but why not just build the SQL statement and then
use

db.Execute mstrSQL, [dbFailOnError]

no querydef required....

Just wondering, that's all.

Apr 15 '06 #3
Private Sub Form_Load()
On Error GoTo Err_Form_Load

Set mdb = CurrentDb

I thought this would execute every time the form opens or loads. But
just in case, I tried it on Form_Open event as well. I still get the
same error.

A guy from my user group gave me this code (the group only meets
monthly, and I was hoping to have this working before then!). I'm new
to all this, but learn well by example and explanation. That's why the
code is as it is.

Any other ideas?
Thanks

Apr 15 '06 #4
pi********@hotmail.com wrote in
news:11**********************@j33g2000cwa.googlegr oups.com:
sounds picky of me, but why not just build the SQL statement and
then use

db.Execute mstrSQL, [dbFailOnError]

no querydef required....

Just wondering, that's all.


I don't see it as picky at all. I almost never edit querydefs in
DAO. I seldom even open them.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Apr 15 '06 #5

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

Similar topics

4
by: Max Harvey | last post by:
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...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
2
by: Steve Jorgensen | last post by:
When writing VB or VBA code that works with databases or other external libraries that cannot be trusted to automatically do the right thing when references to their objects are arbitrarily...
3
by: priscilla.jenkins | last post by:
Alright, I'm really new to SQL and VBA and all this, so I might be completely off course...but just tell me. I know C and Assembly, but that doesn't help me much here. I'm trying to create a...
2
by: BerkshireGuy | last post by:
I have the following code: Dim strSQL As String Dim DB As DAO.Database Dim RS As DAO.Recordset Dim intNumOfPaid, intNumOfHypoed, intNumOfNotTaken, intNumOfDeclined, intNumOfWasted,...
7
by: MLH | last post by:
Consider the following... With MyDB Set qdfA = .CreateQueryDef("NewQry", "Select * From tblData Where_ =True;") Set rstA = .OpenRecordset(qdfA, dbOpenSnapshot) With rstA .MoveFirst Do Until...
1
by: llee | last post by:
Error message says: Syntax error (missing operator) in query expression. When I click on the debug button, it highlights the line I bolded below ( qryDef.SQL = strSQL & " " & strWhere & "" &...
10
by: ineedahelp | last post by:
Can anyone help me figure out why I continue to get a runtime error '3010' "TABLE qryMultiSelect ALREADY EXISTS'? Here is my code. thank you in advance for any help!!! Private Sub...
3
by: Tempalli | last post by:
I am exporting the data from ms access to excel where the error displays as Run-time error -2147467259(800004005) Method 'Copyfromrecordset' of object 'Range' faild. ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.