Link to home
Create AccountLog in
Avatar of ElvasLion
ElvasLion

asked on

CREATE DATABASE with ADO

I again!
This time i need to know how can i create an access database trough vb code. I already know how to create the tables, indexes and all that but i need to know hoe to create the database itself and the odbc file (FileDsn).
Thanks in advance.
Avatar of CJ_S
CJ_S
Flag of Netherlands image

Avatar of CorporateRobot
CorporateRobot

As for the file DSN, you can create one of those using Control Panel.  For example in Windows 98 you choose Start-Settings-Control Panel-ODBC Data Sources.  Then choose the File DSN tab.  
ASKER CERTIFIED SOLUTION
Avatar of dsa7
dsa7

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ElvasLion

ASKER

CJ S
The example is very interesting but that is using the DAO technology right. I want to use the ADO technology.
Thanks Anyway

CorporateRobot
I know how to create a FileDsn in windows i want to create it by code
Thanks to u2

dsa7
Your answer worked just fine but please answer me to the second part of the question and i will give you the points aswell a A grade.
Thanks
You do not need a FileDSN.  After you create the database you can open the access table using the code below.  If you table name has a space in it make sure you put brackets around it in your sql statement like
SELECT * FROM [MY TABLE]

Also, check out the following link
http://msdn.microsoft.com/library/psdk/dasdk/pg_i8kry.htm

If you are going to be using ADO a lot you might want to check out the book ADO 2.6: Programmer's Reference from Wrox publisher.

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
   
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TEMP\MYDATABASE.mdb"

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TEMP\MYDATABASE.mdb;Persist Security Info=False"

rs.Open "SELECT * FROM MYTABLE", cnn, adOpenKeyset, adLockOptimistic

If you really need to create a FileDSN check out the following link which shows you how.

http://www.vb2themax.com/Item.asp?PageID=TipBank&Cat=1000&ID=235
Thanks again for your answer i'm going to check out the links but even if i can't find what i need your answer has already been excellent for 50 points.
thanks again.