craigachan
Registered User.
- Local time
- Yesterday, 16:03
- Joined
- Nov 9, 2007
- Messages
- 285
I have the following code that I used to find an open window so that I won't open it again. I have tracked down somewhere close to what makes MSAccess shut down when the code runs. When it shuts down, no error comes up even though I have error handling. It just shuts down.
I placed, in the 'EnumWindowProcExit:' section a msgbox, and when i = 0 and then recycles thru the code, it crashes. I don't know if this has anything to do with it or not, but it is consistent. Can anyone identify my problem?
Supporting Code
I placed, in the 'EnumWindowProcExit:' section a msgbox, and when i = 0 and then recycles thru the code, it crashes. I don't know if this has anything to do with it or not, but it is consistent. Can anyone identify my problem?
Code:
Public Function EnumWindowProc(ByVal hwnd As Long, lParam As FindWindowParameters, Optional i As Long) As Long
'GROUP CODE: FnFindWindowLike, EnumWindowProc, TrimNull
On Error GoTo EnumWindowProcErr
Dim strWindowTitle As String
strWindowTitle = Space(260)
Call GetWindowText(hwnd, strWindowTitle, 260)
strWindowTitle = TrimNull(strWindowTitle) ' Remove extra null terminator
If strWindowTitle Like lParam.strTitle Then
lParam.hwnd = hwnd 'Store the result for later.
EnumWindowProc = 0 'This will stop enumerating more windows
Else
EnumWindowProc = 1
End If
EnumWindowProcExit:
MsgBox "'" & strWindowTitle & "' - " & i
i = i + 1
Exit Function
EnumWindowProcErr:
MsgBox "WindowAppPublic-EnumWindowProc: " & Err.Number & " - " & Err.Description
Resume EnumWindowProcExit
End Function
Supporting Code
Code:
Public Function TrimNull(strNullTerminatedString As String)
'GROUP CODE: FnFindWindowLike, EnumWindowProc, TrimNull
On Error GoTo TrimNullErr
Dim lngPos As Long
'Remove unnecessary null terminator
lngPos = InStr(strNullTerminatedString, Chr$(0))
If lngPos Then
TrimNull = Left$(strNullTerminatedString, lngPos - 1)
Else
TrimNull = strNullTerminatedString
End If
TrimNullExit:
Exit Function
TrimNullErr:
MsgBox "WindowAppPublic-TrimNull: " & Err.Number & " - " & Err.Description
Resume TrimNullExit
End Function