95 Code Won't Work In 2000

K

Keith Willcocks

I used to use Access 95 VBA but now have to do something in Access 2000.

The following in Declarations:
Dim dbs As Database
Dim rst As Recordset

Followed in a procedure by:
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblMain")

Would open the table for use. However, in Access 2000, this simply results
in error messages. As far as I can see the Database option in "Dim dbs As
Database" no longer works and is giving me Type Mismatch messages. How do
I do this operation in Access 2000 please? Oh, can you keep it simple
please, I haven't touched Access for 6 or 7 years.
 
K

Keith Willcocks

Many thanks for that Allen. I have now installed the DAO Library and
"Database" is now recognised in the Declarations. Curiously though I am
still getting a Type Mismatch message. This is my actual code if you can
see anything daft that I cannot see for the trees:

Declaration:
Dim dbs As Database
Dim rst As Recordset
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private Sub cmdIssuesSubmit_Click()
On Error GoTo Err_cmdIssuesSubmit_Click
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblMain")
rst.MoveFirst

Exit_Err_cmdIssuesSubmit_Click:
Exit Sub

Err_cmdIssuesSubmit_Click:
MsgBox Err.Description
Resume Exit_Err_cmdIssuesSubmit_Click

End Sub

Stepping through in debug with F8, the error message Type Mismatch is thrown
up as soon as the line Set rst = dbs.OpenRecordset("tblMain") is executed.
The table has four short date/time fields and all the others are Text.
There is one record in the table with data in the Primary Key (number 1) and
Text in the first two Text fields. I have rigorously checked all the
spellings in the code.

I am totally puzzled by this and can see no reason for it.

Keith Willcocks
 
A

Allen Browne

Change the line:
Dim rst As DAO.Recordset
to:
Dim rst As Recordset

The ADO library has a Recordset object as well. If you are getting a type
mismatch, Access might be giving you the wrong one, so the above
disambiguates.
 
A

Arvin Meyer [MVP]

Allen mean the opposite:

Change the line:

Dim rst As Recordset

to:

Dim rst As DAO.Recordset
 
K

Keith Willcocks

Oh dear. I was fine with the old 95 version, it's this new fangled stuff
that's messing me up. I made the change to Dim rst As DAO Recordset and
now I am getting the old "Compile error: Expected: end of statement"
message. Sorry to be such a pain, your help and forbearance is greatly
appreciated.

Could there be any other References that I need to include (or exclude)?
The ones I have are:

Visual Basic For Applications
Microsoft Access 10 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Data Object Wizard
Microsoft DAO 3.6 Object Library

Keith Willcocks
 
A

Allen Browne

What line of code generates the compile error that an endof statement is
expected?

With the DAO 3.6 library referenced, the line:
Dim rst As DAO.Recordset
is valid (assuming you don't have something else named rst.)
 
K

Keith Willcocks

I feel such a fool now. It was only in your latest email that my less than
20-20 vision realised there was a full stop (period?) between DAO and
Recordset. Now it works a treat. My most sincere thanks.
 

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

Similar Threads

access2002: type mismatch 1
Error 13 - Type mismatch 8
Code won't run 1
Where is my code wrong? 3
Make table from recordset 2
Message from Access 2007 on sub function 3
Invalid Use of Null 3
Help with recordset 3

Top