Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2005, 10:55 PM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Declaring recordset objects

Here's a portion of code:

Dim thisVoyage As String
Dim db As Database
Dim rec1 As Recordset
Dim id As Long

Set db = CurrentDb()
Set rec1 = db.OpenRecordset("tblLog")

I always get a "type mismatch" error in the last line at run time. Why is this do you think?
 
Old February 21st, 2005, 11:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi Drew,

Common problem. Qualify your recordset object with the name of the library it lives in, in this case DAO:

Dim rec1 As DAO.Recordset

If you check your references, you should see the ADO library listed before the DAO library. When VBA tries to resolve object references, it grabs the object type from the first library listed in your references list that contains the relevant object type. Both ADO and DAO define a Recordset object. So your code thinks its working with an ADO Recordset, not a DAO recordset. (ADO is the default data access library in Access since 2K).

HTH,

Bob






Similar Threads
Thread Thread Starter Forum Replies Last Post
A newer's declaring Ant_Yan J2EE 0 September 15th, 2007 12:35 AM
Declaring a dropdownlist Rod Merritt BOOK: ASP.NET Website Programming Problem-Design-Solution 0 August 1st, 2006 02:11 PM
declaring structs scoobie C++ Programming 3 April 6th, 2006 12:44 AM
declaring variables that are not used crmpicco VB How-To 2 May 19th, 2005 04:22 PM
Declaring and instantiating... jacob ASP.NET 1.0 and 1.1 Basics 4 August 21st, 2003 10:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.