Link to home
Start Free TrialLog in
Avatar of testn1
testn1

asked on

vbs/access file

Hi,

how do i create a vbs or exe? that would create a new MS Access file in a certain directory for a
certain user with her password and it should work on an OS level for the
version of access users have instaled in their local boxes?
Avatar of kmorris1186
kmorris1186

You can create a Access Database using this code:

Set appAccess = CreateObject("Access.Application")
appAccess.NewCurrentDatabase "c:\test.mdb"

i am unsure about setting the password, etc..

This will create an Access DB for the version of Access that is installed on the users machine.
this also means, No Access, No Database.
Sub CreateDatabase(DatabaseName As String, Password As String)

'Ref:
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odeopg/html/deovropeningaccessdatabasebyusingado.asp
' http://support.microsoft.com/?kbid=304915

   Dim objCat As Object 'New ADOX.Catalog
   Dim objConn As Object 'ADODB.Connection
   Dim strAlter As String

    ' create the database
    Set objCat = CreateObject("ADOX.Catalog")
    objCat.Create "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\" & DatabaseName & ";Jet OLEDB:Engine Type=5"
    Set objCat = Nothing
   
   
   
    ' set the password
    Set cn = CreateObject("ADODB.Connection")
    objConn.Mode = adModeShareExclusive 'opens in exclusive mode
    objConn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\" & DatabaseName & ";Uid=;Pwd="
    strAlter = "ALTER Database Password " & Password & "``"
    objConn.Execute strAlter
    Set objConn = Nothing

End Sub
ASKER CERTIFIED SOLUTION
Avatar of avi247
avi247

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial