Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search For Record In SubForm 1

Status
Not open for further replies.

lars7

Technical User
Aug 16, 2005
817
GB
Hi guys,

I'm trying to set the record source for my main form and search within a subform, from a command button on the main form, to find a record but I am getting a type mismatch error with this code:

Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim frm1 As Form
Set frm1 = Forms!FormMain.Form
frm1.RecordSource = "SELECT QueryRecSource.[Pay Number], * " & _
"FROM QueryRecSource " & _
"WHERE QueryRecSource.[Pay Number]= '" & [Forms]![FormMain].Form![FormSubMainLookUp]![PayNo] & "'"

Dim frm2 As Form
Set frm2 = Forms!FormMain.Form!FormSubMainRecords
Dim rs As Object
Set rs = frm2.Recordset.Clone
rs.FindFirst "[RecId] =" & [Forms]![FormMain].Form![FormSubMainLookUp]![RecId]
If Not rs.EOF Then frm2.Bookmark = rs.Bookmark

Can anyone see where I am going wrong?

Thanks in advance.
 
type mismatch error
Which line of code is highlighted when in debug mode ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Ph,
Thanks for replying,

I think the problem is here:

Set frm2 = Forms!FormMain.Form!FormSubMainRecords

when I place the curser over "frm2" I get:

frm2=Nothing




 
Try this:
Set frm2 = Forms!FormMain!FormSubMainRecords.Form

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PH,

I tried all the variations that I knew but once again you have shown me something new.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top