Open Form Based on Value From Main Form

damian

Registered User.
Local time
Today, 00:02
Joined
Jun 27, 2004
Messages
87
Hi

Been trying to open Form2 via a button on a subform (Subform1) which resides on MainForm1. I also want to filter the data based upon a value (Field1) on MainForm1 - been struggling with referencing mainform value despite looking at various posts/websites.

Code so far (will work if button is on the MainForm1 as I used cmd button wizard):

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Form2"

stLinkCriteria = "[Field1]=" & "'" & Me![Field1] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Any assistance would be appreciated
 
Is field1 a number, string or date field??
What is the corresponding field in form2 that you are linking to??
 
Oh, I just spotted you are using this code from a subform and want information from the main form...

Me.Parent will get you to the main form, alternatively if you want to fetch data from the mainform anyways, stick the button on the main form.
 
Thank you for your very prompt and effective solution.

Did the trick, for info:

stLinkCriteria = "[Field1]=" & "'" & Me.Parent.[Field1] & "'"

Did play about with Parent but was using a ! instead of a full stop

Thanks again
 
On a side note, I sure hope you are not actually using "Field1" as your fieldnames?? But instead have meaningfull names??!!
 

Users who are viewing this thread

Back
Top Bottom