| 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] |