Subform and variable

R

Robert_DubYa

I would like to get the value of a cell on a subform when it is clicked on
and place that value into a variable. I have tried to simply go to the
subform, declare the variable in VBA and set the oject of the sub query equal
to the variable. Here is my code in the subquery:

Private Sub Parent_DblClick(Cancel As Integer)

strPegPart = Me.Parent
MsgBox strPegPart

End Sub


This method would works with a regular form but not a subform. I declare
the value of srtPegPart at the form level.

My overall goal is to have the user double click on a part number in the
subform and that populates a text box on the main form that will re-query the
subform. If I can get the msgbox to work correctly I know I can get the
process to work.

thanks!

Robert
 
D

Dale Fye

Robert,

How did you declare strPegPart? Is it public, or private, or did you just
use DIM?

Is Parent the name of the textbox? Personally, I like to add the type of
control to the controls name, to make it easier to destinguish whether I am
referring to a control or to a field. If the subforms data source is linked
to a value in main forms text field, then you should be able to just requery
the subform after setting the value of the control in the main form.

I think something like the following should work:

Private sub txt_Parent_DblClick(Cancel as integer)

'do nothing if the field is blank
if LEN(me.txt_Parent & "") = 0 then Exit sub

'You can probably use the Value property here, but I chose to use
'the text property to account for possible changes in the field before
'the user double clicks in it, but before the record is updated.
me.Parent.txt_SomeControlName = me.txt_Parent.Text
me.requery

End Sub

HTH
Dale
 
R

Robert_DubYa

Dale,

I actually got this to work by using the following:

strPegPart = Forms!frmPeg2![frmPeg2subform].Form![Parent]

I declared strPegPart as public in a module. I later pass this on as a
function that I use to base query criteria upon.

thanks for your help though!

kind regards,
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top