It sounds like you’re experiencing significant delays when starting shell tasks in your MS Access program using VBA’s Shell
function. Here are some potential causes and solutions to consider:
- Resource Contention: Running multiple shell processes in parallel can lead to resource contention, especially if each process is resource intensive. Ensure that your system has sufficient CPU and memory resources available.
Process Management: Your program waits for earlier shell processes to finish before starting new ones. If these processes are not terminating correctly or are taking longer than expected, it could cause delays. Consider adding more robust error handling and logging to track the status and duration of each shell process.
Windows and MS Access Updates: Ensure that both Windows 11 and MS Access are fully updated. Sometimes, updates can resolve performance issues.
Database Size and Optimization: Although your database is below the 2TB limit, its size can still impact performance. Regularly compact and repair your database to optimize performance.
VBA Code Optimization: Review and optimize your VBA code. For example, the Shell
function runs asynchronously by default, which means the next line of code executes immediately. Ensure that your code correctly handles asynchronous execution.
System Performance: Monitor your system’s performance using Task Manager or Resource Monitor to identify any bottlenecks or resource-intensive processes.
Here is a revised version of your code with some additional error handling and logging:
Sub TestShellStart(ByRef PID As Double, ByRef StartDelay As Long)
Dim StartTask As Long
Dim TaskStarted As Long
StartTask = GetTimeStamp()
On Error Resume Next
PID = Shell("powershell.exe & vbCrLf exit /s" & vbCrLf, vbHide)
If Err.Number <> 0 Then
Debug.Print "Error starting shell: " & Err.Description
Err.Clear
End If
On Error GoTo 0
TaskStarted = GetTimeStamp()
StartDelay = TimeDiffMs(StartTask, TaskStarted)
End Sub
Function CheckProcessByPID(PID As Double) As Boolean
Dim objList As Object
Set objList = GetObject("winmgmts:").ExecQuery("select * from win32_process where ProcessID='" & PID & "'")
CheckProcessByPID = (objList.Count > 0)
Set objList = Nothing
End Function
If the issue persists, consider reaching out to Microsoft Support or consulting with a professional who specializes in VBA and MS Access performance optimization. They might be able to provide more specific insights based on your environment and code.