Solved

vbs/access file

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now