Results 1 to 12 of 12

Thread: ADO question?

  1. #1

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Yeah,

    You need to reference Microsoft Active X Data Object 2.X library. Try this and then run the code.

    Also just a side note, to get data from the database your recordsets should look something like this:

    Code:
    dim RS as New Recordset
    RS.Open "SELECT * FROM table",DB,adOpenForwardOnly,adLockReadOnly
    Hope this helps

  2. #2
    Member
    Join Date
    Apr 2000
    Posts
    48
    Negative0,

    I added the reference to ADO 2.X and reran the code and it gave me an error something about "Microsoft Run time error, could not find file". Does the code you provide automatically create the file if it's not there?

    Thanks, Laura

  3. #3
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231
    It doesnt create a file there, you will have to make your own mdb in Access. I have no idea how to create a database programatically, but you need a database to start with if you are going to open it. once you got one, then you can add records into a table etc.
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  4. #4

    Thread Starter
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Sorry,

    I read the post wrong, I thought you just wanted to access the DB, not create it. I am not sure how to create it from code with ADO.


  5. #5
    Member
    Join Date
    Apr 2000
    Posts
    48
    Thanks everyone!

    Does anyone know how to create a "mdb" database using ADO connection thru VB code?

  6. #6
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    This may help...
    Code:
    Sub ADOCreateDBmitTbl()
    Dim cat As New ADOX.Catalog, tbl As New ADOX.Table
      ' create new mdb
      cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=[full_filename, i.e., c:\newkid].mdb;"
      ' if you want to encryt it...
      ' & "Jet OLEDB:Encrypt Database=True;Jet OLEDB:Engine Type=2;"
    
      ' Create a new Table object.
      With tbl
        .Name = "your_tbl_name"
        ' Create fields and append them to new Table object.
        ' You must do this before before appending object
        ' to Tables collection of Catalog.
        .Columns.Append "Field1_name", adVarWChar
        .Columns.Append "Field2_name", adVarWChar
        .Columns.Append "Field3_name", adLongVarWChar
        .Columns("Field3_name").Attributes = adColNullable
        ' yada, yada...
      End With
      ' Add new table to database.
      cat.Tables.Append tbl
      Set cat = Nothing
    End Sub

  7. #7
    Member
    Join Date
    Apr 2000
    Posts
    48
    Mongo,

    The code you posted is to create new Table. What I need
    is to create a new "Database". Is it possible to create
    a new empty database with ADO connection using VB code?

    Thanks, Laura

  8. #8
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    This part creates the new mdb:
    Code:
    cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=[full_filename, i.e., c:\newkid].mdb;"

  9. #9
    Member
    Join Date
    Apr 2000
    Posts
    48
    Mongo, thanks for the reply. I tried your code and it works nicely. I also wanted to add password do you know the syntax for that?

    Laura

  10. #10
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    I believe you add:

    ;Jet OLEDB:Database Password=MyPassword

    to the end of the connection string.....


  11. #11
    Member
    Join Date
    Apr 2000
    Posts
    48
    How do I create an older Access Database?
    What parameters do I use in the cat.create command?

    Thanks, Laura

  12. #12
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    Laura

    Try ';Jet OLEDB:Engine Type=4' in the create bit

    i.e.
    Code:
    cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=[full_filename, i.e., c:\newkid].mdb;" & _
        "Jet OLEDB:Engine Type=4;"
    4 = Access 97
    5 = Access 2000

    Hope this is of use.
    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


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