datatype error in recordset statement

D

DaBartman

Hi guys,
New to Access, so please be kind
The following has been working just fine. Now I get a 'Type Mismatch' error
#13 in the highlighted line. Do not understand this.

Public Sub NewDataAddition(strNewData As String, strTable As String)

Dim db As Database
Dim rec As Recordset ' Adds new data to Casinos and Games tables

Set db = CurrentDb()
Set rec = db.OpenRecordset(strTable) ' this is the offending line

rec.MoveFirst
Do While Not rec.EOF
If rec.Fields(0) <> strNewData Then
rec.MoveNext
Else
rec.Close
Exit Sub
End If
Loop
rec.AddNew
rec.Fields(0) = strNewData
rec.Update
rec.Close

End Sub
 
A

Allen Browne

The DAO and ADO libraries both have a Recordset object, so change the 2nd
line to:
Dim rec As DAO.Recordset
 
D

DaBartman

Thank you very much Allen. Having two libraries has been confusing for at
times. Your solurion worked just fine.
 
A

Allen Browne

Excellent.

BTW, if you are not using the ADO library, you can drop it from your
project. Open a code window, choose References on the Tools menu, and
uncheck the box beside the Ms ActiveX library.

That's the 2nd thing I do whenever I create a new database (immediately
after turning Name AutoCorrect off.)
 

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