'make a access-database in VB4
'make a form1 with one command-button on it
'place the code in the Click_event
Sub Command1_click
Dim antwoord
Dim lokatie$
Dim tb As TableDef
Dim fld As Field
Dim indx As Index
Dim DBNaam$
Dim dbNieuw As Database
'location database
lokatie = InputBox("Where do you want the database placed?", App.Path)
If lokatie = "" Then Unload Form1
If Right(lokatie, 1) <> "\" Then lokatie = lokatie & "\"
'check if directorie exists
antwoord = Dir(lokatie)
'it don't exist so make it
If antwoord = "" Then MkDir (lokatie)
'get name of the new database
antwoord = InputBox("What's the name of the database?")
If antwoord = "" Then Unload Form1
Screen.MousePointer = vbHourglass
'make database
DBNaam$ = lokatie & antwoord & ".mdb"
Set dbNieuw = CreateDatabase(DBNaam$, dbLangGeneral, dbVersion30)
'make a table
Set tb = dbNieuw.CreateTableDef("youretablename")
'make a date-field
Set fld = tb.CreateField("date", dbDate)
tb.Fields.Append fld
'make a meno-field
Set fld = tb.CreateField("omschrijving", dbMemo)
tb.Fields.Append fld
'make a Yes/No field
Set fld = tb.CreateField("alarm", dbBoolean)
tb.Fields.Append fld
'make a text field with a length of 8 characters
Set fld = tb.CreateField("username", dbText, 8)
tb.Fields.Append fld
dbNieuw.TableDefs.Append tb
'make a index on the date-field
Set indx = tb.CreateIndex("date")
Set fld = indx.CreateField("date")
indx.Unique = False
indx.Fields.Append fld
tb.Indexes.Append indx
'make a unique index on the field username
Set indx = tb.CreateIndex("username")
Set fld = indx.CreateField("username")
indx.Unique = True
indx.Fields.Append fld
tb.Indexes.Append indx
Screen.MousePointer = vbNormal
End Sub
Return