How to I create a recordset or DB that I can load through VB?
Printable View
How to I create a recordset or DB that I can load through VB?
.Quote:
Originally Posted by Cipher
You will have to be a bit more descriptive than that.
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
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 SecurityHope that helps. BTW there are some really good tutorials to be found in the Database forum.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