Set Form Property from a Different Form

G

GeyikBaba

In Access 2003 I have a form with a property defined as follows:

Public wtPrelimFinal as string

This form, and a couple of similar forms, call a dialog form where the user
picks between two options.

I want to pass the name of the form and the proprty to the called form as
follows, for example:
"Forms!ThisForm.wtPrelimFinal", using OpenArgs, then storing the string in a
variable, say strForm in the called form.

When the user selects an option, I want to reset the value of wtPrelimFinal
in the calling form.

Hard coded, it would be somthing like:
Forms!ThisForm.wtPrelimFinal = "FINAL"

In the called form, how do I reset the variable in the calling form using
strForm?

EVAL(strForm) = "FINAL" did not work. The error message was asking for an
object.

Many thanks
Mike Thomas
 
D

Douglas J. Steele

It's not really clear to me what your situation is. Are you saying you've
defined a property named "wtPrelimFinal" as a property for the form, are you
saying that you're going to store the name of the property in a variable
named wtPrelimFinal (or both: the property name is "wtPrelimiFinal", and
you're storing what value you want put into that property in variable
wtPrelimFinal)?

Also, you say you want to pass the name of the form, yet you appear to be
passing a reference to the form (Forms!ThisForm is an actual form object,
whereas "ThisForm" would be the name of the form)

If you're trying to pass two values through OpenArgs, the easiest way is
pick some delimiter character, and then parse the OpenArgs string in the
form that was opened. For example, to open frmB and pass the name of frmA
and the argument "Final" to it, you'd use:

DoCmd.OpenForm "frmB", OpenArgs:="frmA;Final"

Then, in the Load event of frmA, you'd have:

Private Sub Form_Load()
Dim strFormName As String
Dim strParameter As String
Dim varArgs As Variant

If IsNull(Me.OpenArgs) = False Then
varArgs = Split(Me.OpenArgs, ";")
If UBound(varArgs) >= 1 Then
strFormName = varArgs(0)
strParameter = varArgs(1)
End If
End If

End Sub

Assuming that frmA (the name of the form passed when opening frmB) is open,
you could then refer to property wtPrelimFinal of frmA as:

Forms(strFormName).wtPrelimFinal = strParameter
 
G

GeyikBaba

Thanks Doug,

My original question was probably overly confusing.

I was just trying to reset one form's (frmA) property value from another
form (frmB). I want to pass in the name of the calling form because several
forms make use of frmB.

The line;

Forms(strFormName).wtPrelimFinal = strParameter

did the trick.

Many thanks,
Mike Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top