Find record in a subform

gregmiii

New member
Local time
Today, 14:37
Joined
Mar 21, 2012
Messages
3
I have an unbound form: frm_ReceiptSearch with some fields that, when something is input, will search a datasheet viewed form on a subform on the main form (subform name is sf_frm_Receipts). Currently, on the txt_CheckNo field's after update event, I have the following code:

Private Sub txt_CheckNo_AfterUpdate()
Dim SrchVar As String

SrchVar = Me.txt_CheckNo

Me!sf_frm_Receipts!REFNO.SetFocus
DoCmd.FindRecord SrchVar, acEntire, , acSearchAll, , acCurrent, True
End Sub

but I'm getting a runtime error 438. Any suggestions?
 
What I usually do is create a SQLstring with a where based on the Srchvar

in the Srchvar_afterupdate I call the function
SetFilterSubform

Dim function SetfilterSubform
Dim Sqlstr as string

SQLstr = the string you use in the recordsource of the subform
if not*isnull(Srchvar)) then
build a where based on Srchvar
endif

me.yoursubform.recordsource = Sqlstring
End function

Hope this makes sense.
 
boerbende,

Thank you for the reply. I follow you, but what I need is for the subform to be in datasheet view with all the records present, but have the SrchVar found record highlighted. I see where you're going, I just don't want to filter down on the WHERE clause.
 
Throwing an error number at readers is pointless - we do not have all the descriptions stored in our heads.

To set focus to something on a subform is not a one-step process as you might think. Google

Access set focus subform
 
spikepl,

Will make sure to not throw out numbers, first post and all that here.

As an update, I've tried a few alternatives, still with no success. Now, on the main (unbounded) form I've got:

Private Sub txt_CheckNo_AfterUpdate()
Dim SrchVar As String

SrchVar = Me.txt_CheckNo

Me!sf_frm_Receipts!REFNO.SetFocus
DoCmd.FindRecord SrchVar, acEntire, , acSearchAll, , acCurrent, True
End Sub

I'm now getting an error message that says "A macro set to one of the current field's properties failed because of an error in a FindRecordd action argument.

The setfocus seems to be working (the REFNO field becomes highlighted prior to the error). Thanks for any help.
 

Users who are viewing this thread

Back
Top Bottom