|
Thread: Mdb
-
Feb 10th, 2005, 05:33 PM
#1
Thread Starter
Junior Member
Mdb
How to I create a recordset or DB that I can load through VB?
"It is a hard thing to fall, it is even harder to admit to that fall."
-Darth Treya
Star Wars: Knights of the Old Republic II
-
Feb 10th, 2005, 05:45 PM
#2
Re: Mdb
 Originally Posted by Cipher
How to I create a recordset or DB that I can load through VB?
.
You will have to be a bit more descriptive than that.
-
Feb 10th, 2005, 05:50 PM
#3
Thread Starter
Junior Member
Re: Mdb
Well you know the Biblio.mdb that comes with VB. How do I make my own mdb.
Mdb= Microsoft Data Base.
Because I want to load the field and tables through VB.
EDIT: Maybe this belongs in DATabase
"It is a hard thing to fall, it is even harder to admit to that fall."
-Darth Treya
Star Wars: Knights of the Old Republic II
-
Feb 10th, 2005, 06:50 PM
#4
Re: Mdb
Here's a code snippet that demonstrates how to create an Access database and a table in the database. You'll need to add references to:
Microsoft ActiveX Data Objects 2.x Library
Microsoft ADO Ext. 2.x for DDL and Security
VB Code:
Public Sub MakeDB()
Dim cat As ADOX.Catalog
Dim cn As ADODB.Connection
Dim newDB As String
Dim DBVersion As Integer
'
' Create a new Access database
' Note: Valid 'Engine Type' 3 is Access2, 4 is Access97, 5 is Access2000
'
newDB = "c:\mynewdb.mdb" ' Path & name of new database
DBVersion = 5 ' Create Access 2000 database
Set cat = New ADOX.Catalog
cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & newDB & ";Jet OLEDB:Engine Type=" & DBVersion
Set cat = Nothing
'
' Create a table in the database
'
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & newDB
Dim sql As String
sql = "create table [mynewtable] ("
sql = sql & "[Surname] TEXT(30), "
sql = sql & "[First Names] TEXT(30), "
sql = sql & "[Business Name] TEXT(40), "
sql = sql & "[Phone] TEXT(16), "
sql = sql & "[Fax] TEXT(16), "
sql = sql & "[Birthdate] DATETIME, "
sql = sql & "[Number of Kids] SMALLINT, "
sql = sql & "[Notes] TEXT(250))"
cn.Execute sql
'
' Create the indexes
'
sql = "create index [Surname] on [mynewtable] ([Surname])"
cn.Execute sql
sql = "create unique index [Business Name] on [mynewtable] ([Business Name])"
cn.Execute sql
cn.Close
Set cn = Nothing
End Sub
Hope that helps. BTW there are some really good tutorials to be found in the Database forum.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|