Setting startup items

R

Rob Bunocore

I have a database that I use to create another database. I use the
following code to do that.

Private Function strCreateAccessDatabase(strDBPath As String) As
String
On Error GoTo ErrorHandler
Dim catNewDB As ADOX.Catalog
Dim strConnect As String
Dim answer As Integer

If Dir(strDBPath) <> "" Then
'MsgBox "This database already exists " & vbCrLf & strDBPath
answer = MsgBox("This database already exists " & vbCrLf &
strDBPath & " Do you wish to overwrite the exisiting file?", vbYesNo,
"File Already Exists")
Select Case answer
Case vbYes
Kill strDBPath
Set catNewDB = New ADOX.Catalog
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
catNewDB.Create strConnect
Set catNewDB = Nothing
strCreateAccessDatabase = strConnect
Case vbNo
Exit Function
End Select
Else

Set catNewDB = New ADOX.Catalog
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
catNewDB.Create strConnect
Set catNewDB = Nothing
strCreateAccessDatabase = strConnect

End If
Exit Function


ErrorHandler:
Set catNewDB = Nothing
End Function

I then set a database password
Private Function setDBPassword(strDBPath As String, strOldPwd As
String, strNewPwd As String)
Dim dbsDB As DAO.Database
Dim strOpenPwd As String

strOpenPwd = ";pwd=" & strOldPwd

Set dbsDB = OpenDatabase(Name:=strDBPath, Options:=True,
ReadOnly:=False, Connect:=strOpenPwd)

With dbsDB
.NewPassword strOldPwd, strNewPwd
.Close
End With

Set dbsDB = Nothing

End Function

The problem is that I want to transfer a macro and name it autoexec in
the target database. Because I save my project as a MDE file, I get
an error saying that it can't change the name of the macro.

DoCmd.TransferDatabase acExport, "Microsoft Access", Me.txtPath,
acMacro, "ImportMacro", "autoexec"

Does anyone have any code that I could use to set the Start up
features in the Target Database?

Thanks.

Robby
 
N

n

Rob Bunocore said:
I have a database that I use to create another database. I use the
following code to do that.

Private Function strCreateAccessDatabase(strDBPath As String) As
String
On Error GoTo ErrorHandler
Dim catNewDB As ADOX.Catalog
Dim strConnect As String
Dim answer As Integer

If Dir(strDBPath) <> "" Then
'MsgBox "This database already exists " & vbCrLf & strDBPath
answer = MsgBox("This database already exists " & vbCrLf &
strDBPath & " Do you wish to overwrite the exisiting file?", vbYesNo,
"File Already Exists")
Select Case answer
Case vbYes
Kill strDBPath
Set catNewDB = New ADOX.Catalog
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
catNewDB.Create strConnect
Set catNewDB = Nothing
strCreateAccessDatabase = strConnect
Case vbNo
Exit Function
End Select
Else

Set catNewDB = New ADOX.Catalog
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
catNewDB.Create strConnect
Set catNewDB = Nothing
strCreateAccessDatabase = strConnect

End If
Exit Function


ErrorHandler:
Set catNewDB = Nothing
End Function

I then set a database password
Private Function setDBPassword(strDBPath As String, strOldPwd As
String, strNewPwd As String)
Dim dbsDB As DAO.Database
Dim strOpenPwd As String

strOpenPwd = ";pwd=" & strOldPwd

Set dbsDB = OpenDatabase(Name:=strDBPath, Options:=True,
ReadOnly:=False, Connect:=strOpenPwd)

With dbsDB
.NewPassword strOldPwd, strNewPwd
.Close
End With

Set dbsDB = Nothing

End Function

The problem is that I want to transfer a macro and name it autoexec in
the target database. Because I save my project as a MDE file, I get
an error saying that it can't change the name of the macro.

DoCmd.TransferDatabase acExport, "Microsoft Access", Me.txtPath,
acMacro, "ImportMacro", "autoexec"

Does anyone have any code that I could use to set the Start up
features in the Target Database?

Thanks.

Robby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top