Referencing a Form with a String Variable? (1 Viewer)

nasa09

Registered User.
Local time
Yesterday, 20:38
Joined
Jun 12, 2015
Messages
41
Is it possible to store a form's name as a string and then refer to that form by that string name?


For instance, I have a form named "frm_payoff_process" that contains a textbox named "txtRecevedTotal", and I can refer to it with the following code:

Code:
Forms!frm_payoff_process!txtReceivedTotal

Now say I had a string variable named "str" in which I stored the name of that form. Would I be able to refer to that control on that form using that variable?

I ask because I have several forms for different processes that all need to send and receive data to/from another "helper" form. I'd like to be able to store the name of the form that calls that helper form so that the helper form knows where to return the data. I'm basically trying to avoid creating multiple identical helper forms tailored to each of my main forms.

Is this possible? Or can anyone offer guidance on a better way to do this?

Any help is greatly appreciated!
 

nasa09

Registered User.
Local time
Yesterday, 20:38
Joined
Jun 12, 2015
Messages
41
I don't think I am, but maybe I'm not fully understanding the info in that link?
 

missinglinq

AWF VIP
Local time
Yesterday, 23:38
Joined
Jun 20, 2003
Messages
6,420
I'm not real clear on what you're trying to accomplish, here, but you could try using a Global Variable.

In a Standard Module declare a Global Variable, using

Public strFormName As String

To set a Form's name to it, use something like

strFormName = Me.Name

Now, on any Form, until the Variable is reassigned, or the Database is closed, you can use strFormName in place of the Form's name.

Like I said, not sure what you're doing, and this may or may not work, for your purpose, but probably worth a try.

Linq ;0)>
 

nasa09

Registered User.
Local time
Yesterday, 20:38
Joined
Jun 12, 2015
Messages
41
Sorry, I had trouble wording my original post just right and I obviously didn't do a very good. Let me try again.

I have a form named frm_payoff_process. The form's purpose is to enter information about incoming payments from clients.

The user enters the amount received into a textbox named txtReceivedTotal and then selects the payment method from a combobox named cboPaymentSources.

Occassionally a client makes payments using two separate methods. For example, they might send a wire and a check to pay off their account. In such cases, the user selects "Multiple Payment Sources" from the combobox.

This prompts a second form to open, named frm_multiple_payments. This second form contains five more textbox/combobox pairs so that the user can enter up to five separate payment sources. Additionally, there is a textbox that shows the total sum of all of the amounts entered into the other textboxes.

When the user has completed their entry on frm_multiple_payments, they click a button. That button sends the value of each amount entered to hidden fields on frm_payoff_process. It also sends the value of that total sum textbox to txtReceivedTotal on frm_payment_process.

This all works great for me and does exactly what I need it to do, in the short term.

The problem is, I have another entry form named frm_partial_process that is very similar to frm_payoff_process that is used to enter information about a different type of transaction. Like frm_payoff_process, this form contains a textbox named txtReceivedTotal and a combobox named cboPaymentSources for the exact same purpose.

What I'd like to do is have frm_multiple_payments store the name of whatever form that calls it, and then when the user enters their data and clicks the button, have frm_multiple_payments send that data to that same stored form.

I could just create another form that's identical to frm_multiple_payments to work with frm_partial_process, but I'd rather make frm_multiple_payments dynamic enough to work with multiple other forms.

Hopefully this made a bit more sense.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 04:38
Joined
Feb 19, 2013
Messages
16,704
I think what you are asking for is

dim str as string
dim formtotal as double

str="frm_payoff_process"
formtotal=forms(str)!txtReceivedTotal
 

nasa09

Registered User.
Local time
Yesterday, 20:38
Joined
Jun 12, 2015
Messages
41
CJ London, thank you so much! That is exactly what I was looking for!!!
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 13:38
Joined
Jan 20, 2009
Messages
12,861
Additionally, consider passing the calling form name as the OpenArgs parameter of the OpenForm Method. It is then available as the OpenArgs Property on the called form.

This encapsulates the passing of the form name with the opening of the form. Much better practice than using global variables.
 

nasa09

Registered User.
Local time
Yesterday, 20:38
Joined
Jun 12, 2015
Messages
41
Hmmm, I'm admittedly still a bit of a novice when it comes to things like this, and I'm definitely interested of getting in the habit of using best practices. Would you mind providing an example of how I might do that?
 

Users who are viewing this thread

Top Bottom