Link to home
Start Free TrialLog in
Avatar of Neil Udovich
Neil UdovichFlag 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]
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
Replace in the code me.Text0 with the actual name of your textbox, like:

    Me!txtYourActualName

/gustav
@220-221

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

Forms!NOINE.nameofControl = Forms(OpenBy)(ctlName)
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
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....
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
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.
Yes, those are the names of the controls on "Noine"

"You can't assign a value to this contract...." is the error.
I'm sorry, Object.  Not Contract.
upload a copy of your db
Rey, I'm sorry.  I can't do that.  I know, it may be the end of the road from a help perspective.
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
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.
create a blank db, import the form Noine from your db

upload the created db.
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.