CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2000
    Posts
    14

    Can't open recordset! Help!

    I'm attempting to open a recordset. I've tried using DAO and ADO...the database opens just fine, but when I try
    set rs=db.openrecordset("<tablename>",opendynaset,openreadonly)
    I get an error saying "Type Mismatch"
    if i try rs.open "<tablename>",db,<options>
    I get "Open method of _recordset object failed"

    what the heck am I doing wrong? I've done it a hundred times in a COM Object, but when i try doing this with a standard EXE, I get all kinds of errors. Any help here would be greatly appreciated. Thanks!
    -Aaron


  2. #2
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Re: Can't open recordset! Help!

    In your References, have you got the Microsoft DAO Object Library 3.5 selected ?


  3. #3
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Can't open recordset! Help!

    Not sure if this is a "typing" problem or not, but opendynaset and openreadonly won't work. The constants are

    dbOpenDynaset
    dbOpenReadonly

    Also I am assuming that above you db.OpenRecordset statement you are doing a corresponding...

    Set db=OpenDatabase("dbname")

    A little more code would help. Hope this is enough to get you going.


  4. #4
    Join Date
    Nov 2000
    Posts
    14

    Re: Can't open recordset! Help!

    Actually, I have 3.51...I've also tried 3.6. I don't have 3.5 as an option.


  5. #5
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Re: Can't open recordset! Help!

    Try this Aaron;

    Dim ADBase As Connection
    Dim ARecs As New ADODB.Recordset

    ProductDBConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source= < Database Name >.mdb;Jet OLEDB;"
    Set ADBase = New Connection
    ADBase.CursorLocation = adUseClient
    ADBase.Open ProductDBConnectionString
    ARecs.Open "SELECT Users.* FROM Users;", ADBase, adOpenStatic



  6. #6
    Join Date
    Nov 2000
    Posts
    14

    Re: Can't open recordset! Help!

    ok, that worked, but unfortunately, I also need to gather a list of the tables within the database and the connection object doesn't seem to support that..Is there an easier way to do this or should I just create a database and connection object and use the db object for the table list and connection object for recordsets? Thanks for all your help!
    -Aaron


  7. #7
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Can't open recordset! Help!

    Sub ListTables()

    Dim cat As New ADOX.Catalog
    Dim tbl As ADOX.Table

    'References : Microsoft ADO Ext 2.1 or DDL and Security

    ' Open the catalog
    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\nwind.mdb;"

    ' Loop through the tables in the database and print their name
    For Each tbl In cat.Tables
    If tbl.Type <> "VIEW" Then Debug.Print tbl.Name
    'not to see system tables If Left$(tbl.Name, 4) <> "MSys" Then Debug.Print tbl.Name

    Next

    End Sub

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  8. #8
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Re: Can't open recordset! Help!

    Hi Aaron,

    If you send me you Email address, I've got a form here, which allows you to select any Access 97 Database via a Common Dialog, It thend fills a TreeView control with all Tables, Queries etc in the Database, you should be able to rip out the code you need.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured