confusing declaration

kgcrowther

Registered User.
Local time
Today, 22:55
Joined
Jun 1, 2001
Messages
52
Some of the most simple things can confuse a beginner. I just want to bring a table in as an object. The following code gives me a type-mismatch error:

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("states")
MsgBox "Record count: " & rs.RecordCount

However, the following code works fine:

Dim rs
Set rs = CurrentDb.OpenRecordset("states")
MsgBox "Record count: " & rs.RecordCount

I seem to be missing something in my fundamental understanding of what the recordset object is. Any insight would be great. (Maybe this is a good thread to have some discussions about a really fundamental programming topic of declaring variable.)

--KGC
Charlottesville, VA, USA
 
While viewing code (or after Alt F11) go to Tools>References and put a check next to
Microsoft DAO 3.6 Object Library. You might want to remove the check from ActiveX if you are not using ADODB anywhere. You can then Dim rs AS DAO.Recordset again with success. When you Dim rs by itself you are defining it as a Variant data type which can handle anything but is not efficient.
 
Thanks RG! I'm not sure I would have figured that out on my own!

Is there a resource to learn more about checking the libraries in Tools->References? I noticed that Matlab is on the list. Does this mean I might be able to use some of the Matlab matrix functions through the VBA part of Access? Does anyone recomend a resource that would teach this aspect of VBA for MS Access??

Thanks for all the ideas.

--KGC
 
You are certainly welcome and glad I could help. Sorry but I can't help with your other question but someone else is bound to drop by and may have an answer. You could always try Google.
 

Users who are viewing this thread

Back
Top Bottom