Solved

vbs/access file

Posted on 2004-09-21
3
200 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:testn1
  • 2
3 Comments
 
LVL 7

Expert Comment

by:kmorris1186
ID: 12117044
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.
0
 
LVL 4

Expert Comment

by:avi247
ID: 12118063
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
0
 
LVL 4

Accepted Solution

by:
avi247 earned 500 total points
ID: 12118158
Oops! Sorry. posted incorrect code above for Setting the Password.. Heres it again. Other things remain same.


    ' set the password
    Set objConn = CreateObject("ADODB.Connection")
    objConn.Mode = adModeShareExclusive 'opens in exclusive mode
    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\TestDB.mdb;Persist Security info=False"
    strAlter = "ALTER Database Password " & Password & " NULL"
    objConn.Execute strAlter
    Set objConn = Nothing

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question