Re: Error 91 help required

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Reggie (NoSpamreggie_at_NoSpamsmittysinet.com)
Date: 07/07/04


Date: Wed, 7 Jul 2004 02:52:20 -0700

Sanda, You need to instantiate the database object variable by using the set
statement as you did for the recordset object. I also changed the name of
your variable. Not sure if CurrentDB is a reserved word, but why take
chances!

Dim db As DAO.Database
Set db = CurrentDb()
Set rs = db.OpenRecordset("qryFirst")

-- 
Reggie
----------
<sandra@discussions.microsoft.com> wrote in message
news:27e1c01c46402$41fa9570$a501280a@phx.gbl...
> Help!
>
> I am getting an Error 91 code "Object variable or With
> block variable not set"
>
> I get it on
>   Set rs = CurrentDb.OpenRecordset("qryFirst")
> from the following code:
>
>   Private Sub cmdSubmit_click()
>
>   Dim rs As DAO.Recordset
>   Dim CurrentDb As Database
>
>   Set rs = CurrentDb.OpenRecordset("qryFirst")
>
>   rs.MoveLast    'I put this in because I've found
>                   sometimes it doesn't count properly
>                   otherwise...
>
>   If rs.RecordCount = 0 Then
>      MsgBox "blah"
>   Else
>      DoCmd.OpenQuery "qryFirst", acViewNormal
>   End If
>
>   End Sub
>
> Any ideas what's causing this error?


Relevant Pages

  • Re: Error 91 help required
    ... If you run the query through the interface, ... Not sure if CurrentDB is a reserved word, ... >>> Private Sub cmdSubmit_click ... >>> Dim rs As DAO.Recordset ...
    (microsoft.public.access.modulesdaovba)
  • RE: Forms are fun (except when they need combo box VBA code I don
    ... Private Sub AgentName_NotInList(NewData As String, Response As Integer) ... Dim db As Database ... Set db = CurrentDb ...
    (microsoft.public.access.formscoding)
  • Repeating pages in Microsoft Access report
    ... and use openrecordset to get the recordset object. ... I display the string in a TextBox object. ... Dim mainString As String ... Private Sub main_Print ...
    (comp.programming)
  • Re: Error 91 help required
    ... You need to instantiate the database object ... >statement as you did for the recordset object. ... Not sure if CurrentDB is a reserved word, ... >> Dim rs As DAO.Recordset ...
    (microsoft.public.access.modulesdaovba)
  • run time error 3075.
    ... Private Sub Item_No_AfterUpdate ... Dim rs As DAO.Recordset ... Set db = CurrentDb() ... The above code is getting a run time error 3075. ...
    (microsoft.public.access.formscoding)