M
Max Yaffe
Dear Group,
I'm having a problem with the following scenario and could use some
help.
I have an form (formPartInfo)with an empty record source. On it is a
combo box (cboPart) with a query (qryPartList) for a row source. I
initialize this form during the Form_Open event using code that looks
like:
Public Sub SetPart(myPart As String)
' Valid Part Number Test
Dim FindPart As String
FindPart = "Part = '" & myPart & "'"
Me.cboPart.Recordset.FindFirst FindPart
If (Me.cboPart.Recordset.NoMatch = True) Then
' Inform user & take corrective action
MsgBox ("Part " + myPart + " is not found)
Me.cboPart = Me.cboPart.ItemData(0)
myPart = Me.cboPart.Value
End If
'Continue on setting record source for form & subforms here
Me.RecordSource = PartQuery(myPart)
Me.sfVendor.Form.RecordSource = VendorQuery(myPart)
' and so forth.
The problem is that sometimes when I do the Valid Part Number Test,
Me.cboPart.Recordset is uninitialized and the test fails with an error
"Run-time error 91. Object or With Variable not set".
Then when I look at "Me.cboPart.Recordset" in the watch window, it is
set to "Nothing". However, if I then look at Me.cboPart in the watch
window, it is set correctly, after which, Me.cboPart.Recordset is set
correctly and the code continues to run!
I've tried this code running from Form_Open and from Form_Load with
the same results.
I guess the question is, when is MyForm.cboMyCombo.Recordset valid
after a form has started to open?
Thanks for your help.
Max
I'm having a problem with the following scenario and could use some
help.
I have an form (formPartInfo)with an empty record source. On it is a
combo box (cboPart) with a query (qryPartList) for a row source. I
initialize this form during the Form_Open event using code that looks
like:
Public Sub SetPart(myPart As String)
' Valid Part Number Test
Dim FindPart As String
FindPart = "Part = '" & myPart & "'"
Me.cboPart.Recordset.FindFirst FindPart
If (Me.cboPart.Recordset.NoMatch = True) Then
' Inform user & take corrective action
MsgBox ("Part " + myPart + " is not found)
Me.cboPart = Me.cboPart.ItemData(0)
myPart = Me.cboPart.Value
End If
'Continue on setting record source for form & subforms here
Me.RecordSource = PartQuery(myPart)
Me.sfVendor.Form.RecordSource = VendorQuery(myPart)
' and so forth.
The problem is that sometimes when I do the Valid Part Number Test,
Me.cboPart.Recordset is uninitialized and the test fails with an error
"Run-time error 91. Object or With Variable not set".
Then when I look at "Me.cboPart.Recordset" in the watch window, it is
set to "Nothing". However, if I then look at Me.cboPart in the watch
window, it is set correctly, after which, Me.cboPart.Recordset is set
correctly and the code continues to run!
I've tried this code running from Form_Open and from Form_Load with
the same results.
I guess the question is, when is MyForm.cboMyCombo.Recordset valid
after a form has started to open?
Thanks for your help.
Max