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

form/subform focus

Status
Not open for further replies.

Krash878

Programmer
May 8, 2001
172
US
I am working on a form that has a subform. The subform is in datasheet veiw. On the Form I have a text box that I want to have linked to the subforms lastname feild. I would like to be able to click on a name in the subform and have the forms textbox populate with the recod that the focus is on and also be able to start typing in to the text box and have focus in the subform highlight the record that the text closest resembles then click on the record and have it again populate into the text box. After this I would have command buttons that would open other forms and reports based on what is in the text box. My question is how do I link the two forms and keep the subform displaying all the data? Right now if I link the two forms the subform will only show one record at a time.
 
You're asking three questions, let me make sure I'm understanding them correctly:
Q1) How do I set a textbox value in a parent form when I select a particular record in a child form?

A1) In the OnCurrent event in the CHILD form, put the following line:
Code:
Me.Parent![TextBox] = Me![Last Name]

Q2) When I type in the text box in the PARENT form, how do I select the record in the child form that is the closest match while still displaying all of the records?
A2) OK, I'm not sure this will do EXACTLY what you want it to since it requires a move out of your TextBox field to activate, but here it is:

Put this code in the AfterUpdate event of the TextBox on the main form:
Code:
Dim strTemp As String
strTemp = Me![TextBox]
Me.EmpSubform.SetFocus
'Assume EmbSubform is name of your subform
Code:
While (strTemp > Me![EmpSubform]![Last Name])
    DoCmd.GoToRecord , , acNext
Wend

While (strTemp < Me![EmpSubform]![Last Name])
    DoCmd.GoToRecord , , acPrevious
Wend
Q3)How do I make the subform display multiple records?
A3) You need to have a 1-to-many relationship between the tables that the forms are based on. The subform on the parent form should have the Link Child and Link Master fields set to the related fields on the two forms.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top