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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Access find button on main form that searches a subform 1

Status
Not open for further replies.

kkalin

Technical User
Jan 26, 2009
2
US
I have a company main form and an account subform and I want to be able to create a find button on the main form that will search a field on the subform. The results will also need the main form data to reset relative to the found data on the subform. Can someone tell me what is the easiest way to do this in Access 2007? Thanks!
 
How are ya kkalin . . .

Not quite sure what your asking. Perhaps if you provide an example! . . .

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1 - kkalin didnt reply, but I need the same thing. The example is below:

Firearms qualification database. The main form has the personnel information (name, address, etc) a subform has their weapon information (make, model ,serial number, etc).

I would like to be able to search for a serial number (sfrm field) and if found, it would set the parent form (personnel) to the matching person who has that weapon.

Forms are linked using an employee ID. Not sure it matters, but the weapon sfrm has its own sfrm (datasheet) that shows the qualification scores for that weapon. They are linked by Employee ID and Weapon SN.

Does that help? This would be great if it can be done.

Thanks

 
Can you use:
Code:
DoCmd.RunCommand acCmdFind

Or some variation thereof? There's FindNext, etc... all used to search the records on a form... or at least I think.. [wink] Not really used it much myself, yet..

Other option, probably best if it's a large data set would be to use a query or SQL for searching the underlying table.

--

"If to err is human, then I must be some kind of human!" -Me
 
How are ya Countymnca . . .

Can be done! 1st you need a combobox based on your [blue]weapons table[/blue] comprising two fields [blue]EmployeeID[/blue] and [blue]Weapon SN[/blue]. The [blue]EmployeeID[/blue] should be the 1st field and hidden in the combobox. Place the combo in the header or footer of the mainform. When your done post back the following:
[ol][li]Name of the subform. [/li]
[li]Name of the combobox.[/li]
[li]Name of EmployeeID (just to be sure) and its datatype (number or text).[/li]
[li]Name of Weapon SN (just to be sure) and its datatype (number or text).[/li]
[li]The RowSource property of the combobox.[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1 -
Here is the info you requested and thanks for the help!

1. WeaponSFRM
2. cboWPNsnSearch
3. EmpID Text
4. WSerialNumber Text
5. SELECT [WeaponTBL].[EmpID], [WeaponTBL].[WSerialNumber] FROM WeaponTBL;

 
OK Countymnca . . .

In the [blue]After Update[/blue] event of the combobox, copy/paste the following:
Code:
[blue]   Dim CBx As ComboBox, sfrm As Form, Cri As String
   
   Set CBx = Me!cboWPNsnSearch
   Set sfrm = [WeaponSFRM].Form
   
   Cri = "[EmpID] = '" & CBx.Column(0) & "'"
   Me.Recordset.FindFirst Cri [green]'Goto Employee[/green]
   
   Cri = "[WSerialNumber] = '" & CBx.Column(1) & "'"
   sfrm.Recordset.FindFirst Cri [green]'Goto weapon SN[/green]
   
   Set sfrm = Nothing
   Set CBx = Nothing[/blue]

Perform your testing!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Works Perfect...thanks!!! I will read up on what you did so I understand it. A star for the help.

 
I am trying to double-click a Record Selector in my subform to populate the mainform with the same record. But I get Error Message 2465 'DATABASE can't find the field "|" referred to in your expression...

=======================
Option Compare Database
Option Explicit

Private Sub Form_DblClick(Cancel As Integer)

Dim TBH As TextBox, sfrm As Form, Cri As String

Set TBH = Me!MemberID
Set sfrm = [ChildrenSubform].Form '< ERROR MSG 2465 POPS UP HERE
Cri = "[MemberID] = '" & TBH & "'"
Me.Recordset.FindFirst Cri 'Goto MemberID of Mainform
Cri = "[MemberID] = '" & TBH & "'"
sfrm.Recordset.FindFirst Cri 'Goto MemberID of Subform
Set sfrm = Nothing
Set TBH = Nothing

End Sub
=======
 
Oblvion,

1. Start your own new thread.
2. For reference, see the links at the bottom of TheAceMan1's signature line.

If you really want to get help, that's how you need to proceed.

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top