Referring to a form with Form("FormName")

not_rich_yet

Registered User.
Local time
Today, 22:21
Joined
Mar 19, 2002
Messages
39
Hi all,

I have a subform which can be opened via a button from numerous main forms. I need to access the main form from the subform to update a value on the main form based on what the user has done with the subform.

I created a textbox on the subform, which gets it's text value set when the button from the main form is clicked. I have it to set the text to the name of the main form from which it was clicked....this works fine, as I can see the name of the main form appearing in the tet box.

I then attempted numerous times to get the following code working, to allow me to update a value on the main form, the code was placed in the Form>Close property of the sub form(s)

Dim strOpenedFrom As String
Me!txtOpenedFrom.SetFocus
strOpenedFrom = txtOpenedFrom.Text
Forms(strOpenedFrom).AppPrice.SetFocus
Forms(strOpenedFrom).AppPrice = Forms(strOpenedFrom).AppPrice + Form_ClientPurchase.Total

Access tells me it cannot find the form I have referred to, even though the text going into the text box on the subform is exactly the same name as used by the code in numerous other places...

Am I missing something here?

Cheers,

nry
 
Not much help really, as it doesn't cover what I want to do: I open a subform via a button from one of many main forms. I then wish to have the subform update a value on the mainform, but this mainform is one of many so the subform needs to know which main form to update, hence cannot use the normal way of accessing forms and controls...

I think Forms("FormName") is the best way to do this but Access tells me it can't find the form I am asking it to...

nry
 
Sorry, I read through your first post too quickly.

I'm pretty sure that when you use Forms( ), that Access is looking for the index number of the form you want, not a string.

If I had a little more time this afternoon, I'd love to help you out, but I have to leave. I hope someone else will read this and give you some clues.
 
Hmm, no, according to Access VBA Help, Forms() can be used with the form index, form name or a string representing the form name....

ActiveForm won't work because I have hmm, around 12 forms open at once!

nry
 
If you are using the OpenForm Method to open forms, you can use the OpenArgs parameter to pass along the name of a form (Me.Name) that opened another form.

If you are actually talking about a subform that appears on multiple main forms, then you can use Me.Parent.Name to obtain the name of the parent form.
 
Hi
I had the same problem myself and solved it this way.

Laborious I know, but at leat it worked for me.


Select Case strOpenedFrom

Case "Form_A"

Forms![Form_A]![AppPrice] = Forms![Form_A]![AppPrice] + Form_ClientPurchase.Total

Case "Form_B"

Forms![Form_B]![AppPrice] = Forms![Form_B]![AppPrice] + Form_ClientPurchase.Total

Case "Form_C"
Forms![Form_C]![AppPrice] = Forms![Form_C]![AppPrice] + Form_ClientPurchase.Total

Case "Form_D"

Forms![Form_D]![AppPrice] = Forms![Form_D]![AppPrice] + Form_ClientPurchase.Total

Case Else

Forms![Form_E]![AppPrice] = Forms![Form_E]![AppPrice] + Form_ClientPurchase.Total

End Select

Best of luck
 
Hi
I had the same problem myself and solved it this way.

Laborious I know, but at leat it worked for me.


Select Case strOpenedFrom

Case "Form_A"

Forms![Form_A]![AppPrice] = Forms![Form_A]![AppPrice] + Form_ClientPurchase.Total

Case "Form_B"

Forms![Form_B]![AppPrice] = Forms![Form_B]![AppPrice] + Form_ClientPurchase.Total

Case "Form_C"
Forms![Form_C]![AppPrice] = Forms![Form_C]![AppPrice] + Form_ClientPurchase.Total

Case "Form_D"

Forms![Form_D]![AppPrice] = Forms![Form_D]![AppPrice] + Form_ClientPurchase.Total

Case Else

Forms![Form_E]![AppPrice] = Forms![Form_E]![AppPrice] + Form_ClientPurchase.Total

End Select

Best of luck
 
Hi
I had the same problem myself and solved it this way.

Laborious I know, but at leat it worked for me.


Select Case strOpenedFrom

Case "Form_A"

Forms![Form_A]![AppPrice] = Forms![Form_A]![AppPrice] + Form_ClientPurchase.Total

Case "Form_B"

Forms![Form_B]![AppPrice] = Forms![Form_B]![AppPrice] + Form_ClientPurchase.Total

Case "Form_C"
Forms![Form_C]![AppPrice] = Forms![Form_C]![AppPrice] + Form_ClientPurchase.Total

Case "Form_D"

Forms![Form_D]![AppPrice] = Forms![Form_D]![AppPrice] + Form_ClientPurchase.Total

Case Else

Forms![Form_E]![AppPrice] = Forms![Form_E]![AppPrice] + Form_ClientPurchase.Total

End Select

Best of luck
 
Hi,

Yeah, I've done it in a very similar way! Not ideal but it works which is all that counts!

Thanks for the help,

nry
 
In order to do that the form must be open!
You can also use Forms!FormName.
 

Users who are viewing this thread

Back
Top Bottom