AccessVandal already wrote what I would have suggested. I generally search
using a combo box in the header, so I completely forgot that you are
searching from a dialog form. Another point is that you may find you need
to keep the dialog form open but hidden. In the main form's Close event you
could have:
DoCmd.Close acForm, "DialogFormName"
The Me prefix references the current form. It is not transferred when that
form closes. In any case, while the dialog form is open Me refers to it, so
Me.lstFirm (or Me!lstFirm) would refer to lstFrm in the dialog form. To
refer to another object, as suggested:
Dim frm as Form
Dim rst As DAO.Recordset
Dim lngSelect As Long
Set frm = Forms!YourFromName
'Check to see if no selection was made.
If IsNull(frm.lstFirm) Then
MsgBox "Make a selection or click Cancel", , "No Selection"
Exit Sub
End If
'Store the selection (firm ID number) in a variable.
lngSelect = frm.lstFirm
'Close the dialog form to switch back to the main form.
Me.Visible = False
'Find the selected record.
Set rst = frm.RecordsetClone
rst.FindFirst "aIDFirm = " & lngSelect
'Check the result
If rst.NoMatch Then
MsgBox "Record not found."
Else
frm.Bookmark = rst.Bookmark
End If
Rather than opening another form you could maybe have the list box in the
header, and make it visible when you click the command button. Or you could
place the list box in the form header and make that visible.
Me.FormHeader.Visible = True
or to toggle it:
Me.FormHeader.Visible = Not Me.FormHeader.Visible
In any case, you will probably want to hide it in the form's Current event.
Just another option to consider. Remember that when referencing one form or
report from code in another form you need to use the full Forms!FormName
reference.
oldblindpew said:
Thank you, BruceM.
I had already tried changing the bangs into dots, although I did not think
a) that I had it wrong, and b) that it would make any difference. It did
not
make any difference.
I followed your instructions and got the step-thru to work. Its funny my
reference book said nothing about having to insert a break point to force
the
execution into break mode. It just said put your cursor where you want
and
press F8 to begin.
Single stepping confirms that Set rst = Me.RecordsetClone generates the
error. "Me" refers to the dialog form initially, and when that is closed
the
firm form becomes the active form, "Me" should refer to it, but it isn't
working. "Me" has to be the object in the expression that is either
closed
or doesn't exist. Weird.