Link to home
Start Free TrialLog in
Avatar of nschulz777
nschulz777

asked on

Create mdb with ADO

Avatar of nschulz777
nschulz777

ASKER

Avatar of Ryan Chong
Hi nschulz777,

Example:

'set a reference to the Microsoft DAO 3.5 Object library then use the code below

Dim ws As Workspace
Dim db As Database

Set ws = DBEngine.Workspaces(0)
'substitute Password with the desired password
Set db = ws.CreateDatabase("test.mdb", dbLangGeneral & ";pwd=Password")

'Hope will help.

Hi,

another sample: Create Database, rename tables, delete fields, create fields and tables, sort, and search.
http://www.vbcode.com/code/DBProject.zip
Look at this:

http://www.vbexplorer.com/sql_ado_database_table.htm
(You would be able to create tables, indexes, keys etc. using ADO.)

Cheers
ryancys, the question is to create mdb with ADO.
Hi guys, sorry about that.
nschulz777: Here is an example of using ADOX to create an MDB. Add a reference to Microsoft ADO Extenstion for Security etc (or something like that) to your project and use a variant of the following example:

Dim catAccess As New ADOX.Catalog
   Dim tblValExp As New ADOX.Table
   Dim cnnAccess As New ADODB.Connection
   Dim rstValExp As New ADODB.Recordset
   catAccess.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb;Jet OLEDB:Engine Type=4;"
   catAccess.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb"
   With tblValExp
       .Name = "tblValExp1"
       .Columns.Append "Stock Name", adVarWChar, 40
       .Columns.Append "Stock Symbol", adVarWChar, 6     '1
       .Columns.Append "Stock Price", adSingle       '2
       .Columns.Append "Est Date", adVarWChar, 10           '3
       .Columns.Append "Est Year", adVarWChar, 6         '4
       .Columns.Append "Price High(0)", adSingle     '5
       .Columns.Append "Price High(1)", adSingle     '6
       .Columns.Append "Price High(2)", adSingle     '7
       .Columns.Append "Price High(3)", adSingle     '8
       .Columns.Append "Price High(4)", adSingle     '9
       .Columns.Append "Price High(5)", adSingle     '10
   End With
   catAccess.Tables.Append tblValExp
   Set tblValExp = Nothing
   Set catAccess = Nothing
   cnnAccess.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\test1.mdb;Persist Security
Info=False"
   rstValExp.Open "SELECT * FROM tblValExp1", cnnAccess, adOpenKeyset, adLockOptimistic
   rstValExp.AddNew
   rstValExp.Fields(0).Value = "Name"
   rstValExp.Fields(1).Value = "Symbol"
   rstValExp.Fields(2).Value = 1.5
   rstValExp.Fields(3).Value = Format(Now(), "dd/mm/yyyy")
   rstValExp.Fields(4).Value = "2000"
   rstValExp.Fields(5).Value = 1.5
   rstValExp.Fields(6).Value = 1.5
   rstValExp.Fields(7).Value = 1.5
   rstValExp.Fields(8).Value = 1.5
   rstValExp.Fields(9).Value = 1.5
   rstValExp.Fields(10).Value = 1.5
   rstValExp.Update
   rstValExp.MoveFirst
   Set rstValExp = Nothing
   Set cnnAccess = Nothing
Thanks all. My question was actually about an ISAM driver problem and unable to post I emailed a member who has been helping me.All good stuff, Ill post any points due if I use it.
If its alright with you guys id like to redirect this question to another one   In creating a install package for a dao driven application im a little confused about the shared files   if someone with access 2000 ran the install would it overwrite their masacces exe and what about the mdactp   will this create problems for them as well
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Tim