Pass value from one form to another

MilaK

Registered User.
Local time
Today, 15:12
Joined
Feb 9, 2015
Messages
285
Hello,

There are two linked tables: “tblRuns” (primary key Run_name) and “tblVariants (also contains Run_name but not as a primary key). There are two continuous forms representing each table.
There is a textbox next to each record on frmRuns. When the textbox is clicked, I expect to open frmVariants and display variants for that particular run.
Also, I need to pass selected “run_name” value from frmRuns to a textbox “txtCurrentRun” on frmVariants.
When I use the following code I get prompted to enter parameter value for query and after I enter the parameter value I get “Object required” error at frmVariants.txtCurrentRun.Value = Me.Run_Name.
I don’t understand why I get prompted to enter a parameter, also, please explain how to pass the run_name to a textbox. Thank you very much.
Here is the code:

Code:
 [FONT=Calibri]Private Sub First_Review_Completed_Click()[/FONT]
  
 [FONT=Calibri] 'if record exists show correspondin records in 'frmVariants'
                DoCmd.OpenForm "frmVariants", _
                    WhereCondition:="Run_Name=" & Me.Run_Name
                    frmVariants.txtCurrentRun.Value = Me.Run_Name
[/FONT][FONT=Calibri]End Sub[/FONT]
 
use the full path: (use the text box names, not field names, but they could be the same)
forms!frmRuns!txtCurrentRun= forms!frmRuns!run_name

and just use the values, not param names. And if its string , use quotes:
DoCmd.OpenForm "frmVariants",,,"[Run_Name]='" & Me.Run_Name & "'"
 
Thank this worked, however, there is a listbox on frmVariants that has the following query as the row source and it fails to populate when frmVariants opens. I've tried to re-query but it's still blank. Any suggestions? Thanks

Code:
Private Sub Form_Load()

Me.lstTumorType.Requery

End Sub

SELECT DISTINCT tblVariants.Sample_Type
FROM tblVariants
WHERE (((tblVariants.Run_Name)=[Forms]![frmReview_One]![txtCurrentRun]));
 
This has something to do with passing value of Run_name to the txtCurrentRun because the listbox populates fine if I bind txtCurrentRun to a table.
 
If the main form uses a text box, then the first test I would try is to set a breakpoint in the secondary form's _Load code.

When it opens, do a

debug.print [Forms]![frmReview_One]![txtCurrentRun]

This might not come back with a value - but if it gives you an error, that might be useful to know what it doesn't like. If it is totally silent, then you are no worse off than you were before.
 
It does pass the value to txtCurrent run, however, the listbox appears blank. However, when I switch to Design View and back to form view the listbox populates. Thanks
 
Ok, I solved it. I need to requery after the textbox is clicked on frmRuns and not on Form Load of frmVariants.

Forms!frmVariants!lstTumorType.Requery
 

Users who are viewing this thread

Back
Top Bottom