
April 14th, 2006, 09:15 PM
| | | 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 |

April 14th, 2006, 10:35 PM
| | | Re: Error on QueryDef on Close
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" <saraqpost@yahoo.com> wrote in message
news:1145044784.481673.137030@j33g2000cwa.googlegr oups.com...[color=blue]
> 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
>[/color] | 
April 15th, 2006, 03:15 AM
| | | Re: Error on QueryDef on Close
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. | 
April 15th, 2006, 01:55 PM
| | | Re: Error on QueryDef on Close
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 | 
April 15th, 2006, 04:25 PM
| | | Re: Error on QueryDef on Close pietlinden@hotmail.com wrote in
news:1145066759.909258.279390@j33g2000cwa.googlegr oups.com:
[color=blue]
> 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.[/color]
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/ | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 205,414 network members.
|