Setting a DAO Referrence through code

R

Rob Bunocore

I have a situation where the main database exports certain data. The
process is that it creates a new database, gives it a name, runs some
make table queries to populate tables inside the new database, exports
a form, gives the database a password, ext. One of the forms that
gets export has code on it that requries a DAO Referrence. Since I'm
creating this entire database through code, is there a way I can set
the referrence using code as well?

Here is a summary of the code that I already run.


Private Sub cmdExportData_Click()
Dim path As String
Dim file As String
Dim strPathNew As String
Dim theTool
Dim strLocalFE As String
Dim strLocalFE2 As String
Dim computer As String
Dim sScrFile As String

file = Me.txtFileName_user & "-" & Format(Now(), "hhnn") & ".mdb"
path = CurrentProject.path & "\" & file

'Create Database
strCreateAccessDatabase (path)

'Run Make Table Queries
Call TransferTables_LU(path, "LU_CaseTypes")

'Transfer Queries
Call TranferQueries(path)

'Create Database Password
Call setDBPassword(path, "", "nanhir")

'Delete the data from the system
Call DataExport_DeleteData

'Renames the database that was created to move it to another
directory.
'Name path As strPathNew

'Last steps
MsgBox "Your data has been exported into a new database, " &
strPathNew & "."

'DoCmd.Close

End Sub


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


Private Function setDBPassword(strDBPath As String, strOldPwd As
String, strNewPwd As String)
Dim dbsDB As DAO.Database
Dim strOpenPwd As String
Dim P As DAO.Property
Dim Prp As DAO.Property

strOpenPwd = ";pwd=" & strOldPwd

Set dbsDB = OpenDatabase(Name:=strDBPath, Options:=True,
ReadOnly:=False, Connect:=strOpenPwd)
Set P = dbsDB.CreateProperty("StartupForm", dbText, "frmImport",
False)
Set Prp = dbsDB.CreateProperty("StartupShowDBWindow", dbBoolean, True,
True)

With dbsDB
.NewPassword strOldPwd, strNewPwd
'.Properties.Append P
'.Properties.Append Prp
.Properties("StartupForm") = "frmImport"
.Properties("StartupShowDBWindow") = False
.Close
End With

Set dbsDB = Nothing

End Function
 
G

Guest

You are getting ahead of yourself. How do you intend to create
the new database? Have you worked out how to 'export' the
form? Have you tried it yet? If so, which method did you use?

I think you may be better to use a database template, which
already has the DAO reference, and probably already has
the form.

If you already have a database with a form, then yes, you can
add a reference in code, but you will probably have to do it in
a different order.

(david)
 

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