Solved

vbs/access file

Posted on 2004-09-21
3
199 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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