Set Value on a Button

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

How do you set the value and label on a command button from a field on a
nother form.

Whe I open a new form fromanother form I want the button to hold the
value from a field on th efirst form, also I want it to take that fields
value as a label.
Any help, appreciated,
Thanks
DS
 
How do you set the value and label on a command button from a field on a
nother form.

Whe I open a new form fromanother form I want the button to hold the
value from a field on th efirst form, also I want it to take that fields
value as a label.
Any help, appreciated,
Thanks
DS

You can pass the value of the control on formA to formB using the
form's OpenArgs argument.

DoCmd.OpenForm "FormB", , , , , , [ControlName]

Code the FormB Load event:
If Not IsNull(Me.OpenArgs) Then
Me!CommandName.Caption = Me.OpenArgs
End If

A comand buttons can't retain a value, but in code, you can refer to
the value of OpenArgs later whenever you need that value.

Dim strC as Integer
strC = Me.OpenArgs

Note: OpenArgs is a String value. If you need to work with the value
as a Number, use Val(Me.OpenArgs)
Dim C as Double
C = Val(Me.OpenArgs) *.75
 
Lynn said:
Buttons are not really designed to hold values, but to call procedures and
functions. Can you tell us a little more about what you are wanting?
I kinda, well actually I did this. I had the buton pass the value from
the other form back to another field on the form, As far as the Caption
goes I just set the C
aption property in VBA to the text box on the other form and this worked
great!
Thank you for your help.
DS
 
fredg said:
How do you set the value and label on a command button from a field on a
nother form.

Whe I open a new form fromanother form I want the button to hold the
value from a field on th efirst form, also I want it to take that fields
value as a label.
Any help, appreciated,
Thanks
DS


You can pass the value of the control on formA to formB using the
form's OpenArgs argument.

DoCmd.OpenForm "FormB", , , , , , [ControlName]

Code the FormB Load event:
If Not IsNull(Me.OpenArgs) Then
Me!CommandName.Caption = Me.OpenArgs
End If

A comand buttons can't retain a value, but in code, you can refer to
the value of OpenArgs later whenever you need that value.

Dim strC as Integer
strC = Me.OpenArgs

Note: OpenArgs is a String value. If you need to work with the value
as a Number, use Val(Me.OpenArgs)
Dim C as Double
C = Val(Me.OpenArgs) *.75
Thanks, I'll keep your suggestion on file in case mine blows up......see
previuos post for what I did. Thank You.
DS
 
Back
Top