Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jun 2004
    Location
    Lambertville, New Jersey, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Type mismatch in Acc 2003 (2003)

    I have some code that I wrote in Acc 2002 that works fine but gives me a Type Mismatch error in 2003. The error occurs on an "OpenRecordset" command.
    Any ideas?
    Here's the code:

    Dim db As Database
    Dim rs As Recordset
    Dim strsql As String
    Dim strMsg As String

    Set db = CurrentDb
    strsql = "Select * from tblusers where tblUsers.UserID = '" & _
    strID & "' and tblUsers.UserPassword = '" & strPW & "';"

    Set rs = db.OpenRecordset(strsql) ' Error occurs here

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Type mismatch in Acc 2003 (2003)

    1) Make sure that you have a reference to the Microsoft DAO 3.6 Object Library in Tools | References...

    2) It is a good idea to specify DAO objects explicitly, so that no confusion can occur (Recordset is both a DAO and an ADO object):

    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    (The same holds for declaration of Connection, Field, Index and Property objects)

  3. #3
    Star Lounger
    Join Date
    Jun 2004
    Location
    Lambertville, New Jersey, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Type mismatch in Acc 2003 (2003)

    Hans;
    Thanks for the quick response. Actually, I already had the reference to DAO 3.6 but it was below some ActiveX references. I moved it up the list and it worked fine.
    Thanks very much
    Lance

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Type mismatch in Acc 2003 (2003)

    Even if you move the reference up, it is still recommended to make the declarations explicit. It not only avoids the problem you experienced (you're not dependent on the order of the references any more), but it also makes it easier to maintain and debug the code.

  5. #5
    Star Lounger
    Join Date
    Jun 2004
    Location
    Lambertville, New Jersey, USA
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Type mismatch in Acc 2003 (2003)

    Understood.
    Thanks,
    Lance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •