Run-time error '91' Object variable or With block variable not set

  • Thread starter Sue R via AccessMonster.com
  • Start date
S

Sue R via AccessMonster.com

I have taken over a db and do not know VB, so I would appreciate any help
with this. A form opens to add information for a new contact. there is a
button on the form that is to automatically add a Reference ID. When I click
the button I get the message 'Run-time error'91' Object variable or With
block variable not set. This is the Debug info with rsMain.Requery
hightlighted.

Sub modSetReferenceID(frmMain As Form, strIDValue1 As String, strIDValue2 As
String, txtReference As TextBox)

rsMain.Requery
txtReference.SetFocus
If txtReference.Text = "" Then
If rsMain.RecordCount <= 8 Then
txtReference.Value = strIDValue1 & rsMain.RecordCount + 1
Else
txtReference.Value = strIDValue2 & rsMain.RecordCount + 1
End If
End If

End Sub

Thanks for any help
sue
 
K

Keith Wilby

Sue R via AccessMonster.com said:
I have taken over a db and do not know VB, so I would appreciate any help
with this. A form opens to add information for a new contact. there is a
button on the form that is to automatically add a Reference ID. When I
click
the button I get the message 'Run-time error'91' Object variable or With
block variable not set. This is the Debug info with rsMain.Requery
hightlighted.

Sub modSetReferenceID(frmMain As Form, strIDValue1 As String, strIDValue2
As
String, txtReference As TextBox)

rsMain.Requery
txtReference.SetFocus
If txtReference.Text = "" Then
If rsMain.RecordCount <= 8 Then
txtReference.Value = strIDValue1 & rsMain.RecordCount + 1
Else
txtReference.Value = strIDValue2 & rsMain.RecordCount + 1
End If
End If

End Sub

rsMain is not declared nor is it set to actually be anything. Typically
you'd have something like:

Dim db As DAO.Database, rsMain As DAO.Recordset, strSQL As String
Set db = CurrentDB
strSQL = "Select * from tblMyTable"
Set rsMain = db.OpenRecordset(strSQL)

which kind of suggests that there's a chunk of code missing. Does the code
compile without error? Have you posted all of the code?

Keith.
www.keithwilby.com
 
G

Guest

It would appear that rsMain is a recordset that has be declared in another
sub or function. variables and object declared in a sub or function are not
visible outside that procedure. If you need a variable or object to be
visible anywhere in your form module, you will need to declare it at the
module level.

Look in your code for something like
Dim rsMain as Recordset
Dim rsMain as DAO.Recordset
Dim rstMain as ADO.Recordset

First, be sure it is not declared in multiple procedures. If it is, remove
every occurance of that Dim. Move the Dim to the top of the module, just
below all the Option statements.
 
S

Sue R via AccessMonster.com

Thanks to both of you for your replies - I had exported all of the tables,
etc. into a new database and apparently that does not bring over all of the
required VB programming. I'm at a loss as to how it was all originally set
up so will go back to working on the original one. I had exported into a new
db in ver. 2002 from 2000 as I am unable to open it in 2002...still trying to
figure that one out!...guess I'll keep working in 2000.
Thanks again
Sue

Keith said:
I have taken over a db and do not know VB, so I would appreciate any help
with this. A form opens to add information for a new contact. there is a
[quoted text clipped - 19 lines]

rsMain is not declared nor is it set to actually be anything. Typically
you'd have something like:

Dim db As DAO.Database, rsMain As DAO.Recordset, strSQL As String
Set db = CurrentDB
strSQL = "Select * from tblMyTable"
Set rsMain = db.OpenRecordset(strSQL)

which kind of suggests that there's a chunk of code missing. Does the code
compile without error? Have you posted all of the code?

Keith.
www.keithwilby.com
 
G

Guest

If you want to convert you database from 2000 to 2002, first make a backup :)

Then from the main toolbar select Tools, Database Utilities, Convert.
Select your version and follow the bouncing ball.

Sue R via AccessMonster.com said:
Thanks to both of you for your replies - I had exported all of the tables,
etc. into a new database and apparently that does not bring over all of the
required VB programming. I'm at a loss as to how it was all originally set
up so will go back to working on the original one. I had exported into a new
db in ver. 2002 from 2000 as I am unable to open it in 2002...still trying to
figure that one out!...guess I'll keep working in 2000.
Thanks again
Sue

Keith said:
I have taken over a db and do not know VB, so I would appreciate any help
with this. A form opens to add information for a new contact. there is a
[quoted text clipped - 19 lines]

rsMain is not declared nor is it set to actually be anything. Typically
you'd have something like:

Dim db As DAO.Database, rsMain As DAO.Recordset, strSQL As String
Set db = CurrentDB
strSQL = "Select * from tblMyTable"
Set rsMain = db.OpenRecordset(strSQL)

which kind of suggests that there's a chunk of code missing. Does the code
compile without error? Have you posted all of the code?

Keith.
www.keithwilby.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top