I have found the code on how to do this by googling but I still cant seem to find the explanation on how to implement it
this is what is in my module caled OpenAll Databases
Code:
Option Compare Database
Sub OpenAllDatabases(pfInit As Boolean)
' Open a handle to all databases and keep it open during the entire time the application runs.
' Params : pfInit TRUE to initialize (call when application starts)
' FALSE to close (call when application ends)
' Source : Total Visual SourceBook
Dim x As Integer
Dim strName As String
Dim strMsg As String
' Maximum number of back end databases to link
Const cintMaxDatabases As Integer = 2
' List of databases kept in a static array so we can close them later
Static dbsOpen() As DAO.Database
If pfInit Then
ReDim dbsOpen(1 To cintMaxDatabases)
For x = 1 To cintMaxDatabases
' Specify your back end databases
Select Case x
Case 1:
strName = "MyDatabasePathHere"
Case 2:
strName = "MyDatabasePathHere"
End Select
strMsg = ""
On Error Resume Next
Set dbsOpen(x) = OpenDatabase(strName)
If Err.Number > 0 Then
strMsg = "Trouble opening database: " & strName & vbCrLf & _
"Make sure the drive is available." & vbCrLf & _
"Error: " & Err.Description & " (" & Err.Number & ")"
End If
On Error GoTo 0
If strMsg <> "" Then
MsgBox strMsg
Exit For
End If
Next x
Else
On Error Resume Next
For x = 1 To cintMaxDatabases
dbsOpen(x).Close
Next x
End If
End Sub
The problem is I have tried several methods to get this to run and none of them work.
I have a form that opens when the database opens. I just can't figure out how to get this to run. I have tried the following:
1. in the on open event of the form type OpenAllDatabases = True
2. in the on open event of the form use Macro builder and use macro OpenVisualBasicModule. Then tried putting true in the procedure and tired OpenAllDatases = true on the first line but none of it worked.
What is the proper way to implement this