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

Reference value from a field in a subform

Status
Not open for further replies.

jvanderw

Technical User
Aug 13, 2003
28
0
0
US
Hey all,
Here is my problem. I have a subform that displays data from a query. I want to be able to select a record in the subform and click a button that will set a text box to the value of the id field of the subform. How do I do that?
Textbox123.value = ????????
Thanks for the help,
Josh
 
me.subFrmName.Controls("controlName").value

--------------------
Procrastinate Now!
 
Thanks for the tip, but I tried this:
Forms.[test].[ID].Value = Forms.BankDepSortsubform.Controls("ID").Value
and it didn't work. I tried us me. instead of forms. as well. It gives the error "Run-time error 438. Object doesn't support this property or method."
Any idea why I am getting the error?
Thanks,
Josh
 
Hi,

I think i have an idea of what you want to do. Create a textbox in your subform footer call it say: fieldtxt. Go to the control source of your textbox and enter: =yourfieldname. This could be your id field. On your main form go to the textbox you want to dispaly details, on its control source enter: =[Subform name]![fieldtxt]. The fieldtxt is the textbox you created in the subform footer.

HTH,

M-.
 
Command Button on the Mainform / TextBox on MainForm
Code:
Me.MyTextBox.Value = Me.MySubForm.Form.MyField.Value
Command Button on the SubForm / TextBox on MainForm
Code:
Forms!MyMainForm.MyTextBox.Value = Me.MyField.Value



Zameer Abdulla
[sub]Jack of Visual Basic Programming, Master in Dining & Sleeping[/sub]
Visit Me
 
Thanks for all of your help. I ended up replacing the subform with a multi select list box. Then put a button on the form that calls a function:
Call GetBankDepRecord(BankDepList)
where BankDepList is the name of the list box
Here is the function:
Public Function GetBankDepRecord(ControlName) As String
Dim varitm As Variant
Dim dbs As DAO.Database
Set dbs = CurrentDb
For Each varitm In ControlName.ItemsSelected
Forms![bankdeplookup]!BankDepRecord.Value = ControlName.Column(1, varitm)
Next

End Function
Thanks again.
Josh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top