Solved Record Selection in Continuous Form

markmywords

New member
Local time
, 21:32
Joined
Aug 17, 2024
Messages
3
Greetings All -

I have a data form that includes a search subform for contracts (unique "ContractID"). The subform is continous. It uses an unbound text field that dynamically filters the returned records on key up. Whether before or after filtering - if a record is clicked in the subform, the main form is filtered to that record using "ContractID". All works just fine as-is. What I'd like to explore is the possibility of automatically "clicking" the record in the continuous subform when the record count =1. Seems logical enough, but I have yet to figure it out. Any input would be appreciated.
 
Hi. Welcome to AWF!

What does "clicking" the record in the subform do? Do you have some VBA code in the subform for that? If so, you can simply call it.
 
Simple enough, clicking on the contract number in the search subform filters the parent form like this:

Private Sub ContractNumber_Click()
Me.Parent.Form.Filter = "[ContractID] = " & [ContractID]
Me.Parent.Form.FilterOn = True
Me.Parent.Refresh
End Sub

I'd just like that to be automatic when the number of records filters down to just one.
 
Then, you could try something like:
Code:
If Me.SubformControlname.Form.Recordset.Recordcount = 1 Then
    Call Me.SubformControlname.Form.ContractNumber_Click()
End If
If you get an error, you could try changing the Private Sub into a Public Sub.
 
Slight modification:
Installed this on the AfterUpdate event of the search box in the header of the subform:

Private Sub txtNameFilter_AfterUpdate()
If Me.Recordset.RecordCount = 1 Then
Call ContractNumber_Click
End If
End Sub

Works like a champ, thanks very much!
 
Slight modification:
Installed this on the AfterUpdate event of the search box in the header of the subform:

Private Sub txtNameFilter_AfterUpdate()
If Me.Recordset.RecordCount = 1 Then
Call ContractNumber_Click
End If
End Sub

Works like a champ, thanks very much!
Good job! Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom