Avatar of Neil Udovich
Neil Udovich
Flag for United States of America asked on

Pass Variable Form Name to another form in Access

I have three forms.
A, B, C On which all the field names are standard
I have a second form (NOINE) which I would only like to code once.
When A is open and I push a button I want NOINE to open and reference fields on form A
When B is open and I push a button I want NOINE to open and reference fields on form B

How do I pass the form name as a variable so in my text fields on Form Noine I am effectively referencing it like this

[Forms]![FormA]![Standard Field Name Across all forms A, B, C]

[Forms]![Whatever Variable Name I Pass from the button]![Standard Field Name Across all forms A, B, C]
VBAMicrosoft Access

Avatar of undefined
Last Comment
Neil Udovich

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Neil Udovich

ASKER
Thanks Rey,
I can always count on you for an answer.  
I put the load event in NOINE and I get "Method or data member not found" and me.Text0=   is highlighted in the code.

Assuming I get past that then how do I reference the variable in the text fields

[Forms]![FormA]![TextField1] would now be [Forms]![????]![TextField1]

Thank you
Gustav Brock

Replace in the code me.Text0 with the actual name of your textbox, like:

    Me!txtYourActualName

/gustav
Rey Obrero (Capricorn1)

@220-221

what is the name of the control in form "NOINE"

Forms!NOINE.nameofControl = Forms(OpenBy)(ctlName)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Neil Udovich

ASKER
I was hoping to  pass  10 standard text fields and labels to noine from variable forms a,b,c.  Those fields have standard names call them x,y,z
Rey Obrero (Capricorn1)

ok, stop us from guessing...

what are the actual names of the controls in form "NOINE"?

what are the actual names of the controls in forms A,B,C?

use this for passing control values to form "NOINE"

Forms!NOINE.FieldText1 = Forms(OpenBy)("FieldText1")
Forms!NOINE.FieldText2 = Forms(OpenBy)("FieldText2")
Forms!NOINE.FieldText3 = Forms(OpenBy)("FieldText3")

etc....
Neil Udovich

ASKER
The name of controls are ACTA, ACTB, ACTC, ACTD
I'll focus on
So....
In the click event on Noine I have this

DoCmd.OpenForm "Noine", OpenArgs:=Me.Name & "|ACTA"

In the Load event on the second form I have this.
Private Sub Form_Load()
Dim OpenBy As String, ctlName As String
If Me.OpenArgs & "" <> "" Then
    OpenBy = Split(Me.OpenArgs, "|")(0)
    ctlName = Split(Me.OpenArgs, "|")(1)
 
Me.ACTA = Forms(OpenBy)(ctlName)    <----I'm getting errors thrown here


End If
End Sub
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Rey Obrero (Capricorn1)

please answer this questions

1. The name of controls are ACTA, ACTB, ACTC, ACTD  >> are these the names of controls in form "Noine" ?

2. Me.ACTA = Forms(OpenBy)(ctlName)    <----I'm getting errors thrown here >>>  what is the error?


It would be better if you can just upload a copy of your db.
Neil Udovich

ASKER
Yes, those are the names of the controls on "Noine"

"You can't assign a value to this contract...." is the error.
Neil Udovich

ASKER
I'm sorry, Object.  Not Contract.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Rey Obrero (Capricorn1)

upload a copy of your db
Neil Udovich

ASKER
Rey, I'm sorry.  I can't do that.  I know, it may be the end of the road from a help perspective.
Rey Obrero (Capricorn1)

are you adding or editing records from form noine?

is the form noine bound to a  table or query?

if query, what is the sql statement of the query? post it here
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Neil Udovich

ASKER
No bound table or query.  Noine is a form that only receives values from A,B or C.
On Noine we have a button that will push data to a table but that should be irrelevant.
Rey Obrero (Capricorn1)

create a blank db, import the form Noine from your db

upload the created db.
Neil Udovich

ASKER
SOLVED:  Rebuilt both forms.  Something on NONE was causing that error.

Added second variable as such

DoCmd.OpenForm "Noine", OpenArgs:=Me.Name & "|ACTB" & "|ACTB"


Private Sub Form_Load()
Dim OpenBy As String, ctlName As String
If Me.OpenArgs & "" <> "" Then
    OpenBy = Split(Me.OpenArgs, "|")(0)
    ctlName = Split(Me.OpenArgs, "|")(1)
 
Forms!Noine.ACTA = Forms(OpenBy)("ACTA")
Forms!Noine.ACTB = Forms(OpenBy)("ACTB")

End If
End Sub


Form Noine has the two fields named ACTA and ACTB each with the corresponding value from the variable form name.
THANK YOU.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck