VBS Scripts To Create An Access Database

 

Here you will find a VBS script to create an empty or blank Microsoft Access database based on the name you specify from an input box. You will also find an additional VBS script that will perform the same function as described above but will add sample columns to the access database.

 

VBS Script To Create An Empty Access database

 

strFileName = InputBox("Enter Access File Name",, "MyAccessDatabase")

 

Set objCatalog = CreateObject("ADOX.Catalog")

objCatalog.Create "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & strFileName & ".Mdb" & ";"

 

Set objCatalog = Nothing

MsgBox "Done"

 

Note: You do not need to add the file extension (.Mdb) for the database you want to create as the file extension is automatically added to the filename taken from the input box.

 

VBS Script To Create An Access Database And Add Table Columns

 

strFileName = InputBox("Enter Access File Name",, "MyAccessDatabase")

 

Set objCatalog = CreateObject("ADOX.Catalog")

objCatalog.Create "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & strFileName & ".Mdb" & ";"

 

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Open _

"Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & strFileName & ".Mdb" & ";"

 

objConnection.Execute "Create Table MyTable(" & _

"ID Counter," & _

"TextBox Text(50)," & _

"NumberBox Integer," & _

"MemoBox Memo," & _

"TimeAndDate DateTime)"

 

objConnection.Close

Set objCatalog = Nothing

Set objConnection  = Nothing

 

MsgBox "Done"

 

Note: Change the MyTable name to the name of the table you want to create.

 

The script above like the first script does not require you to specify the access database file extension. The samples above are designed to provide you with a few of available data types that are more common to access development such as the Counter, Text, Integer, Memo and Date-Time.

 

Published Sunday, October 28, 2007 8:39 AM by dhite
Filed under:

Comments

No Comments