DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Type mismatch error with declaration

  1. #1
    Carol Guest

    Type mismatch error with declaration


    Hi!

    I was trying to retrieve database's info into listbox. First, i created a
    form called "parent". In form "parent", i added a property called "getdb"
    to get the database info. Second, i created function "AddCompName" in module
    and try to retrieve database's info into the other form's listbox. the program
    listed below. I was confused by the declaration in the function because i
    wouldn't declare rs as recordset because it would give me a type mismatch
    error. Without the declaration, the program ran correctly. Would someone
    tell me why?

    Public Property Get getdb() As Database
    Set getdb = db
    'Debug.Print "getdb="; getdb.Name
    End Property


    Public Function AddCompName(box As ListBox) As Integer

    dim rs as recordset

    Set rs = parent.getdb.OpenRecordset(sqlCompName, dbOpenDynaset, dbInconsistent,
    dbOptimistic)

    Do While Not rs.EOF

    box.AddItem rs("Name")

    rs.MoveNext
    Loop


    Thanks!

  2. #2
    Anthony Jones Guest

    Re: Type mismatch error with declaration

    Carol.

    I'm a little confused by you message but it seems you are saying that you
    get a type mismatch when assigning a recordset to the variable rs.

    If so check your projects references. I'm guessing you have references to
    both MS ActiveX Data Objects (ADO) and MS DAO. It seems from your code
    that you are using DAO. You could remove the reference to ADO but if you
    need ADO as well then you should use declare variables with an explicit
    library name i.e..,

    Dim rs as DAO.RecordSet

    VB resolves type names by searching the referenced libraries in the order
    they are referenced. If you haven't deliberately re-order the references
    ADO typically is found in list above DAO. Hence an unqualified type
    recordset is assumed to be an ADO recordset by VB. You could move DAO
    above ADO however when you have references to libraries the expose the same
    type names it's best to declare all variables explicitly for both
    libraries.

    BTW,

    >Without the declaration, the program ran correctly


    The above statement in your message indicates your modules do not include
    the Option Explicit directive at the top. You will save yourself a lot of
    grief if you include this in all your modules. VB will put this in all new
    modules automatically if you select the Require Explicit Declaration in the
    VB options.

    Note this doesn't mean you have to explicitly specify libraries for you
    types but it does mean that every variable must be explicitly declared with
    either a Dim, Public or Private statement.

    --
    Anthony Jones
    Nuesoft Ltd




  3. #3
    Anthony Jones Guest

    Re: Type mismatch error with declaration

    Carol.

    I'm a little confused by you message but it seems you are saying that you
    get a type mismatch when assigning a recordset to the variable rs.

    If so check your projects references. I'm guessing you have references to
    both MS ActiveX Data Objects (ADO) and MS DAO. It seems from your code
    that you are using DAO. You could remove the reference to ADO but if you
    need ADO as well then you should use declare variables with an explicit
    library name i.e..,

    Dim rs as DAO.RecordSet

    VB resolves type names by searching the referenced libraries in the order
    they are referenced. If you haven't deliberately re-order the references
    ADO typically is found in list above DAO. Hence an unqualified type
    recordset is assumed to be an ADO recordset by VB. You could move DAO
    above ADO however when you have references to libraries the expose the same
    type names it's best to declare all variables explicitly for both
    libraries.

    BTW,

    >Without the declaration, the program ran correctly


    The above statement in your message indicates your modules do not include
    the Option Explicit directive at the top. You will save yourself a lot of
    grief if you include this in all your modules. VB will put this in all new
    modules automatically if you select the Require Explicit Declaration in the
    VB options.

    Note this doesn't mean you have to explicitly specify libraries for you
    types but it does mean that every variable must be explicitly declared with
    either a Dim, Public or Private statement.

    --
    Anthony Jones
    Nuesoft Ltd




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center