I have a database that I have split into a backend (tables) and frontend (all the other stuff). The backend DB resides on a network fileshare/server and the performance of editing queries and opening tables is less than desirable...
I found this procedure online that says by keeping the backend database open (persistent connection), it will dramatically increase the frontend DB performance.
Here is the text and procedure. My question pertains to the top part where it says "call the procedure" on the application start... How exactly??? I've tried tagging the procedure on the "OnOpen" command of the Main Menu form but that doesn't work or I've got the syntax wrong...
Any advice?? Much appreciated for any sage suggestions...
The DAO OpenDatabase Method
To create a persistent connection to the linked database, open a MS Access database variable in VBA using the DAO OpenDatabase method. Keep this variable open as long as your application is running.
The procedure below supports multiple backend databases. Edit the section with the list of databases to open, then call this when your application starts:
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)
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 = "H:\folder\Backend1.mdb"
Case 2:
strName = "H:\folder\Backend2.mdb"
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
I found this procedure online that says by keeping the backend database open (persistent connection), it will dramatically increase the frontend DB performance.
Here is the text and procedure. My question pertains to the top part where it says "call the procedure" on the application start... How exactly??? I've tried tagging the procedure on the "OnOpen" command of the Main Menu form but that doesn't work or I've got the syntax wrong...
Any advice?? Much appreciated for any sage suggestions...
The DAO OpenDatabase Method
To create a persistent connection to the linked database, open a MS Access database variable in VBA using the DAO OpenDatabase method. Keep this variable open as long as your application is running.
The procedure below supports multiple backend databases. Edit the section with the list of databases to open, then call this when your application starts:
OpenAllDatabases True
When you finish, call this to close the database variables/handles:OpenAllDatabases False
Here's the procedure code: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)
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 = "H:\folder\Backend1.mdb"
Case 2:
strName = "H:\folder\Backend2.mdb"
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