VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Dynamically Create Databases (.MDB's) in code

by Kenny Sendel (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

This code creates a Microsoft Access MDB dynamically.

Assumes
This sample code will create a database in the temp directory with the following fields: fldForeName fldSurname fldDOB fldFurtherDetails
API Declarations
NONE

Rate Dynamically Create Databases (.MDB's) in code

''
'' PUT THIS BEHIND A COMMAND BUTTON TO TEST
''
' Declarations
Dim tdExample      As TableDef
Dim fldForeName     As Field
Dim fldSurname     As Field
Dim fldDOB       As Field
Dim fldFurtherDetails  As Field
Dim dbDatabase     As Database
Dim sNewDBPathAndName  As String
' Set the new database path and name in string (using time:seconds for some randomality
sNewDBPathAndName = "c:\temp\NewDB" & Right$(Time, 2) & ".mdb"
' Create a new .MDB file (empty at creation point!)
Set dbDatabase = CreateDatabase(sNewDBPathAndName, dbLangGeneral, dbEncrypt)
' Create new TableDef (table called 'Example')
Set tdExample = dbDatabase.CreateTableDef("Example")
' Add fields to tdfTitleDetail.
Set fldForeName = tdExample.CreateField("Fore_Name", dbText, 20)
Set fldSurname = tdExample.CreateField("Surname", dbText, 20)
Set fldDOB = tdExample.CreateField("DOB", dbDate)
Set fldFurtherDetails = tdExample.CreateField("Further_Details", dbMemo)
' Append the field objects to the TableDef
tdExample.Fields.Append fldForeName
tdExample.Fields.Append fldSurname
tdExample.Fields.Append fldDOB
tdExample.Fields.Append fldFurtherDetails
' Save TableDef definition by appending it to TableDefs collection.
dbDatabase.TableDefs.Append tdExample
MsgBox "New .MDB Created - '" & sNewDBPathAndName & "'", vbInformation
' Now look for the new .MDB using File Manager!

Download this snippet    Add to My Saved Code

Dynamically Create Databases (.MDB's) in code Comments

No comments have been posted about Dynamically Create Databases (.MDB's) in code. Why not be the first to post a comment about Dynamically Create Databases (.MDB's) in code.

Post your comment

Subject:
Message:
0/1000 characters