Hi, I have the following code in a module
And in my project I use following snippet in form activate event
Occasionally (while in the ide) I get a 'Object variable or with block not set' error. Doing some testing I find that Callingform(hWnd) is nothing, but if I press run again, it continues and produces no error. I just don't know what to do to fix this.
TIA
David Paulson
Code:
Public Function CallingForm(ByVal hWnd As Long) As Form
'Return the Form that launched the given Window
Dim lHwnd As Long
Dim oForm As Form
'get the Handle of the Window that Loaded this Window
lHwnd = GetNextWindow(hWnd, GW_HWNDNEXT)
'Find a match in the "Forms" collection
'and return a reference to it
For Each oForm In Forms
If oForm.hWnd = lHwnd Then
Set CallingForm = oForm
Exit For
End If
Next
End Function
Code:
If CallingForm(hWnd).Name = "frmMonthEndRoutine" Then ' <==== error here
If Month(CompanyYearEnd) + frmMonthEndRoutine.CurrentMonthEnd <= 12 Then
For SEARCH = 0 To cboYear.ListCount - 1
If CLng(cboYear.List(SEARCH)) = CLng(frmMonthEndRoutine.cboYear.Text) - 1 Then
cboYear.Text = cboYear.List(SEARCH)
Exit For
End If
Next SEARCH
Else
TIA
David Paulson