Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch in Recordset assignment 1

Status
Not open for further replies.

RobWalls

Programmer
Jul 25, 2001
15
0
0
GB
I need to add data to a table using a function in a module. I have tried defining the table as a Recordset as follows:

Dim rstMain As Recordset

Set rstMain = CurrentDb.OpenRecordset("tblMain")
With rstMain
.AddNew
!Field1 = "New Data"
!Field2 = "More New Data"
End With

rstMain.Close

but i get an error "Type Mismatch" on the line "Set rstMain..."
What am i doing wrong and how can i get round it? Any advice gratefully received,

Rob
 
Hi

Which version of Acecss (2000 or 2002 I guess right?)

You need to add a reference to DAO, as in versions after A97, ADO is the default access method

Open any code module in design view, go to Tools \ References and DAo library

to avoid confusion change your code to

:

Dim rstMain As DAO.Recordset

Set rstMain = CurrentDb.OpenRecordset("tblMain")
With rstMain
.AddNew
!Field1 = "New Data"
!Field2 = "More New Data"
End With

rstMain.Close





Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Brilliant! Thanks very much - that worked a treat.
Now i am being slightly more ambitious, how can i embed a jpeg in one of the fields? I can do it successfully from a form, but how would i do it in this context? The only thing i've seen is as below (given that i have a field called Jpeg which takes OLE objects);

Dim rstMain As DAO.Recordset

Set rstMain = CurrentDb.OpenRecordset("tblMain")
With rstMain
.AddNew
!Field1 = "New Data"
!Field2 = "More New Data"
!Jpeg.CreateEmbed "C:\Windows\Circles.jpg"
End With

rstMain.Close[\b]

but .CreateEmbed threw up the error "Method or Data Member not found". Any ideas what i need to do? By the way, you were right - i am using Access 2000.
Thanks again for your help,

Rob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top