My team were working with access 2000, where we have our MDB project. This application(ERP) could open around 20 access forms. After we decide migrate our entire system to Acces
Building off of the VM tracking code provided by Mint, I've made a sort of 'Early warning' system for my application that warns you when the VM is approaching a point where it'll start causing problems and recommend a reboot. It's slightly annoying, but until someone comes up with a better solution to 32-Bit Office running in a 64-Bit OS environment, it'll have to do.
ReturnVM: Returns the Virtual Memory usage in GB, triggers alert if it's over 1.425GB. I've found that this works for my application giving as much time between restarts while still allowing some leeway to finish work before restarting. Feel free to adjust as needed.
os_Restart: Writes a batch file that kills the active Access process, deletes the leftover laccdb file and restarts the application (provided everything's on the user's desktop). After writing the file, it executes the batch. Another function deletes this file on application start.
TempVars!tv_WinUID = Environ("USERNAME")
Function ReturnVM() As Double
Dim Mem As MEMORYSTATUS
Dim Result As Integer
Mem.dwLength = Len(Mem)
GlobalMemoryStatus Mem
ReturnVM = Format((Mem.dwTotalVirtual - Mem.dwAvailVirtual) / 1073741824, "0.000")
Debug.Print ReturnVM & " GB of VM used."
If (ReturnVM >= 1.425) Then
DoEvents
Result = MsgBox("Office Virtual Memory usage is approaching the pre-set limit." & vbCrLf & vbCrLf & "To prevent a possible crash, please click 'OK' to restart immediately." & vbCrLf & vbCrLf & "You may click 'Cancel' to finish what you're working on, but if you do, please restart the application as soon as possible.", vbOKCancel)
If (Result = vbOK) Then
os_Restart
End If
End If
End Function
Public Function os_Restart()
Dim fso As Object
Dim oFile As Object
Dim BatchContents As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile("C:\Users\" & TempVars!tv_WinUID & "\Desktop\RestartAccess.bat")
BatchContents = "@echo Restarting Application..." & vbCrLf & _
"@echo off" & vbCrLf & _
"taskkill /f /im MSACCESS.EXE" & vbCrLf & _
"ping -n 6 127.0.0.1 > nul" & vbCrLf & _
"del " & Chr(34) & "C:\Users\" & TempVars!tv_WinUID & "\Desktop\Application.laccdb" & Chr(34) & vbCrLf & _
"start " & Chr(34) & Chr(34) & " " & Chr(34) & "C:\Users\" & TempVars!tv_WinUID & "\Desktop\Application.accdb" & Chr(34)
DoEvents
'Debug.Print BatchContents
oFile.WriteLine BatchContents
oFile.Close
Set fso = Nothing
Set oFile = Nothing
Call Shell("C:\users\" & TempVars!tv_WinUID & "\Desktop\RestartAccess.bat")
End Function