Type Mismatch

G

Guest

Hello,

When I try to run the following code:

Dim rec1 As Recordset
Dim dbs1 As Database

Set dbs1 = CurrentDb
Set rec1 = dbs1.OpenRecordset("GTGrantApplInfo")


With rec1
..AddNew
!Grant_Number = Me![Grant_Number]
!Appl_Recvd_Date = Me![Appl_Recvd_Date]
!Grantee_Number = Me![Grantee_Number]
!GS_Empl_Num = Me![GS_Empl_Num]
!PS_Empl_Num = Me![PS_Empl_Num]
!Notes = Me![Notes]
!Gabi_Disk_Recvd = Me![Gabi_Disk_Recvd]
!Act_Type_Num = Me![Act_Type_Num]
!Prog_Off_Num = Me![Prog_Off_Num]
!Program_Type_Code = Me![Program_Type_Code]
!Period_Year = Me![Period_Year]
!Funding_Per_Begin = Me![Funding_Per_Begin]
!Funding_Per_End = Me![Funding_Per_End]
..Update
End With

I keep getting a Type Mismatch error at line ( Set rec1 =
dbs1.OpenRecordset("GTGrantApplInfo")

The table name used to be GT_Grant_Appl_Info, so I removed the (underscores)
and created one word. I then tried to remove the " , but the table wasn't
recognized by the code. I'm not sure what else to do. Please help

Thanks in advance
 
J

John Vinson

I keep getting a Type Mismatch error at line ( Set rec1 =
dbs1.OpenRecordset("GTGrantApplInfo")

Check Tools... References. Is there a checkmark by Microsoft DAO x.xx
Object Library? How about Microsoft ActiveX Data Objects?

I'd suggest explicitly specifying the DAO object library (which is the
datataype returned by the OpenRecordset method):

Dim dbs1 AS DAO.Recordset

John W. Vinson[MVP]
 
D

Douglas J Steele

Actually, the fact that it's not complaining about Dim dbs1 As Database
should indicate that the DAO reference is present.

Disambiguating as Dim rec1 As DAO.Recordset is definitely in order: the
Recordset object exists in both the ADO and DAO models, and since the
reference to ADO is going to be higher in the list than the reference to
DAO, the ambiguous Dim rec1 As Recordset will result in an ADO recordset.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
G

Guest

Thanks Douglas,

This worked great.

One other question, If I declare all of my variables using "Early Binding"
(dim rst as ado.recordset), does this mean that I don't have to manua
llyselect References from the Tools menu?

If true, how do I find out which references goes with which type of variable
(ie: recordset, database, wordobject, date, etc...)?

Thanks again

And thanks to all who repsonded to this thread.
 
D

Douglas J Steele

No, if you're using Early Binding, then you MUST have a reference. It's Late
Binding that doesn't require a reference to be set.

In answer to your second question, though, you can use the Object Browser.
Hit F2 when you're in the VB Editor.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 

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

Multiple criteria on StLinkCriteria 3
Backend Database 16
Assigning data from a table to a variable 4
FindFirst error 3
VBA Code Locks Up Database 2
Access2000: 2
Multiple criteria on StLinkCriteria 1
Type Mismatch 3

Top