Home All Groups Group Topic Archive Search About

Error 91 after compiling but not during runtime

Author
29 Nov 2007 11:42 AM
Co
Hi All,

I have created a VB program which opens a DAO database and recordset.
When I use the program in runtime there is no problem but when I
compile the program
and try to run if again I'm getting the error 91 Object
variable .......

The problem is this line:
Set rs = db.OpenRecordSet(sql, dbOpenDynaSet)

I have declared the db and rs:

Public db as DAO.Database
Public rs as DAO.Recordset

Anyone knows where this strange behaviour comes from?

Author
29 Nov 2007 1:29 PM
Ralph
Show quote
"Co" <vonclausow***@gmail.com> wrote in message
news:fdfb2833-5689-481c-980f-ec403234da82@o6g2000hsd.googlegroups.com...
> Hi All,
>
> I have created a VB program which opens a DAO database and recordset.
> When I use the program in runtime there is no problem but when I
> compile the program
> and try to run if again I'm getting the error 91 Object
> variable .......
>
> The problem is this line:
> Set rs = db.OpenRecordSet(sql, dbOpenDynaSet)
>
> I have declared the db and rs:
>
> Public db as DAO.Database
> Public rs as DAO.Recordset
>
> Anyone knows where this strange behaviour comes from?
>

'db' isn't initialized.
Add one of the following.
Set db = CurrentDb()
Set db = dbEngine.OpenDatabase(...)
Author
29 Nov 2007 1:38 PM
Norm Cook
Show quote
"Co" <vonclausow***@gmail.com> wrote in message
news:fdfb2833-5689-481c-980f-ec403234da82@o6g2000hsd.googlegroups.com...
> Hi All,
>
> I have created a VB program which opens a DAO database and recordset.
> When I use the program in runtime there is no problem but when I
> compile the program
> and try to run if again I'm getting the error 91 Object
> variable .......
>
> The problem is this line:
> Set rs = db.OpenRecordSet(sql, dbOpenDynaSet)
>
> I have declared the db and rs:
>
> Public db as DAO.Database
> Public rs as DAO.Recordset
>
> Anyone knows where this strange behaviour comes from?

What does your
Set db =
line look like?
Author
29 Nov 2007 6:41 PM
Co
Show quote
On 29 nov, 14:38, "Norm Cook" <normcookNOS***@cableone.net> wrote:
> "Co" <vonclausow***@gmail.com> wrote in message
>
> news:fdfb2833-5689-481c-980f-ec403234da82@o6g2000hsd.googlegroups.com...
>
>
>
> > Hi All,
>
> > I have created a VB program which opens a DAO database and recordset.
> > When I use the program in runtime there is no problem but when I
> > compile the program
> > and try to run if again I'm getting the error 91 Object
> > variable .......
>
> > The problem is this line:
> > Set rs = db.OpenRecordSet(sql, dbOpenDynaSet)
>
> > I have declared the db and rs:
>
> > Public db as DAO.Database
> > Public rs as DAO.Recordset
>
> > Anyone knows where this strange behaviour comes from?
>
> What does your
> Set db =
> line look like?

Set db = OpenWorkspaces(0).dbEngine.OpenDatabase(...)
Author
29 Nov 2007 7:54 PM
Ralph
Show quote
"Co" <vonclausow***@gmail.com> wrote in message
news:cd994c3e-db98-4a00-9afe-c2f14bdcc20a@i29g2000prf.googlegroups.com...
> On 29 nov, 14:38, "Norm Cook" <normcookNOS***@cableone.net> wrote:
> > "Co" <vonclausow***@gmail.com> wrote in message
> >
> > news:fdfb2833-5689-481c-980f-ec403234da82@o6g2000hsd.googlegroups.com...
> >
> >
> >
> > > Hi All,
> >
> > > I have created a VB program which opens a DAO database and recordset.
> > > When I use the program in runtime there is no problem but when I
> > > compile the program
> > > and try to run if again I'm getting the error 91 Object
> > > variable .......
> >
> > > The problem is this line:
> > > Set rs = db.OpenRecordSet(sql, dbOpenDynaSet)
> >
> > > I have declared the db and rs:
> >
> > > Public db as DAO.Database
> > > Public rs as DAO.Recordset
> >
> > > Anyone knows where this strange behaviour comes from?
> >
> > What does your
> > Set db =
> > line look like?
>
> Set db = OpenWorkspaces(0).dbEngine.OpenDatabase(...)

What's an "OpenWorkspaces"?

It looks like you're making it more convoluted than it has to be. The
DBEngine object is the main object. It contains two collections: Workspaces
and Errors. Workspaces is the default so you can access it without a
explicit reference. If you need a Workspace then fetch it from the DBEngine.

Dim ws as DAO.Workspace
Dim db as DAO.Database
Set ws=DBEngine.Workspaces(0)
set db=ws.OpenDatabase(...)

Otherwise just use the DBEngine.

-ralph

AddThis Social Bookmark Button