Referring to text in a table on a subform

RichS

Healthy software!
Local time
Today, 05:30
Joined
Apr 16, 2008
Messages
44
I have a form with a subform that has a table on it. The subform table is a price list with the fields Description, Details (which is hidden as it's too big for the table) and Price.

I want to be able to double-click on a chosen item from the table to display a pop-up showing the same details but with the Details field shown. I have the pop-up in place but I am struggling with displaying the chosen information.

How do I reference the fields on the chosen line in the table?
 
I want to be able to double-click on a chosen item from the table
...
...
How do I reference the fields on the chosen line in the table?
depends on where you are referencing from

Assuming your form is based in a table called tblPrices and you have an autonumber field called PricePK

if from vba code in the form then use something like

e.g. docmd.openform "myForm",,,"PricePK=" & me.pricepk


if from a query or recordsource to another form (and from your description the record you want is on a subform) then

forms!mymainformname!subformcontrolname.Form!PricePK

change the bits in red to do what you want
 
Thanks for your reply.

The subform has a table with the fields 'Description', 'Details' and 'Cost'. I am opening a new form by double-clicking on the 'Description' field. I want to be able to display the fields related to the 'Description' field I clicked on in the pop-up form. I tried Forms![subform]![Description] as the source but that doesn't work...
 
Thanks again for your input. After re-reading your previous post and the article you provided the link to, I understand the way to link to fields on a subform in general. I am now using:

Forms![mainform name]![subform control].Form![field name]
Code:

However, my subform is not based on a standard table but a query so I don't know how to get the reference for the specific line I'm clicking on.
 
it will be whatever row has the focus - i.e. last clicked on. If you haven't clicked on a row then it will be the first row.

It always helps to post the code you are actually using rather than the pseudo code such as

Forms![mainform name]![subform control].Form![field name]

The reason is that you have made up the pseudo code whereas it is your actual code that is the problem.

It's a bit like you going along to the garage and saying 'my car has broken down but here's a drawing'
 
RichS,

Since you just want to pop up a form to show the "Details", it will be easier to use OpenArgs to send the text to the pop up form and display it.

In the subform where "Details" is available but hidden, you create a double-click event:

Private Sub Details_DblClick()
DoCmd.OpenForm "frmDetails",,,,,acDialog,Nz(Me.Details)
End Sub


And in the pop up form, frmDetails, you create an unbound field "Details" and at Form_Load event:

Private Sub Form_Load()
Details = Nz(Me.OpenArgs)
End Sub

One advantage of using OpenArgs is that it is easy to test it.

Good luck.

Shoji
 
Last edited:

Users who are viewing this thread

Back
Top Bottom