473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to replace the name of a form within the syntax with the value in a textbox?

15 Byte
I have a form that contains 3 sub forms with the names sub1, sub2 and sub3. Each sub form has a button that pops up the same form. When the user clicks on the sub form button, the name of the sub form that called the popup form is stored in a hidden textbox so that the name of the sub form can be used to requery the sub form once the popup form is closed. The syntax to requery the sub form is:
Expand|Select|Wrap|Line Numbers
  1. Forms!Mainform!Subform.Requery 
In this syntax, how do I write the code to replace the word ‘Subform’ with the value in the textbox?
Jan 23 '19 #1

✓ answered by twinnyfo

PrivateGuy,

Did NeoPa's solution work for you? I received an error when I referred to the Controls....

I have just tested the following syntax and it does, in fact, requery the referred subform:

Expand|Select|Wrap|Line Numbers
  1. Forms!frmMainForm.Form(Me.txtFormName).Requery
Replace frmMainForm with the actual name of the main form to which you are referring.

Replace txtFormName with the actual name of the control that holds the name of the subform you want to requery.

Hope this hepps!

18 1460
twinnyfo
3,653 Expert Mod 2GB
privateguy,

It may be as simple as:

Expand|Select|Wrap|Line Numbers
  1. Forms!Mainform!(Me.txtBoxName).Requery
An interesting approach that I have not seen before.
Jan 23 '19 #2
privateguy
15 Byte
twinnyfo,

Thanks for responding. I wish it was that simple. Unfortunately, that does not work. It causes the following error "Compile error: Expected identifier or bracketed expression."
Jan 23 '19 #3
privateguy
15 Byte
twinnyfo,

I tried using brackets as well. Using "me" causes another error.
Removing the "me" causes the error that it cannot find the field.
Jan 23 '19 #4
twinnyfo
3,653 Expert Mod 2GB
Try

Expand|Select|Wrap|Line Numbers
  1. Forms!Mainform!(" & Me.txtBoxName & ").Requery
I know we are chasing here, but there must be a combination of characters and codes that allow it to recognize the Form.
Jan 23 '19 #5
privateguy
15 Byte
It causes an error as well. The "(" after the "!" causes the first error. I tried using a string. I tried assigning a textbox value to a variable, but both did not work as well.
Jan 23 '19 #6
NeoPa
32,556 Expert Mod 16PB
Subforms are actually Controls. The Forms on those Subforms are not Subforms - even if they are used as sub-forms.

Syntax for handling Subforms and their forms can be found at Referring to Items on a Sub-Form.

As long as the string passed to the Form that you open is the name of the Subform control, and I would also suggest you pass the name of the main form too for full flexibility, you can use the following syntax to refer to the Subform's Form object :
Expand|Select|Wrap|Line Numbers
  1. Forms(MainFormName).Controls(SubFormName).Form
Thus, to Requery, use :
Expand|Select|Wrap|Line Numbers
  1. Forms(MainFormName).Controls(SubFormName).Form.Requery
Or even :
Expand|Select|Wrap|Line Numbers
  1. Forms(MainFormName).Controls(SubFormName).Requery
Jan 24 '19 #7
privateguy
15 Byte
NeoPa, thank you for responding. Your article on how to refer to forms and sub forms is awesome; however, that is not my problem. The syntax that I am using works if I hard code the name of the sub form. My problem is trying to use a variable for the name of the sub form so that I can use the value in the textbox.
Jan 24 '19 #8
NeoPa
32,556 Expert Mod 16PB
And you don't believe the answer to that is in the linked article?

Bizarre, but no problem. I also included it more specifically in my post.

Let me know if you still have difficulty seeing your solution.
Jan 24 '19 #9
twinnyfo
3,653 Expert Mod 2GB
One more shot:

Expand|Select|Wrap|Line Numbers
  1. Forms!Mainform(Me.txtBoxName).Requery
I forgot to remove the “!” In the previous examples.
Jan 25 '19 #10
Rabbit
12,516 Expert Mod 8TB
I'm confused as to why you even need to bother with storing the name of the subform in a hidden control. If you have a line of code to set that value in the hidden control, you may as well refresh the subform directly without this extra middle step?
Jan 25 '19 #11
privateguy
15 Byte
NeoPa, I did not see the solution to my problem in your post. I understand that sub forms are controls as well as the syntax to reference the appropriate control. Your post does not state, for my problem, how to take the value of the textbox, which can change, and insert it into the syntax without causing an error. I was hoping there was a way to accomplish this with only a few lines of code instead of me having to writing many lines of code if I were to use the Select Case statement. Thank you for trying to help.
Jan 25 '19 #12
privateguy
15 Byte
twinnyfo, I tried that as well. The error it produced was that it could not find the field. I have tried using strings, setting the value of the textbox as a control without any success. Unless some other guru knows of a way to do this, I am going to be stuck with using the Select Case statement. I appreciate you giving thought to my problem.
Jan 25 '19 #13
privateguy
15 Byte
Rabbit, if I only had one sub form, there would be no need to do it the way that I am; however, if I have let's say 20 sub forms that contain unique data, it makes sense to only re-query the sub form that was edited. I hope this gives you clarity. Thank you for responding.
Jan 25 '19 #14
NeoPa
32,556 Expert Mod 16PB
PrivateGuy:
In this syntax, how do I write the code to replace the word ‘Subform’ with the value in the textbox?
Let's review :
Expand|Select|Wrap|Line Numbers
  1. Forms(MainFormName).Controls(SubFormName).Requery
I now understand you're having difficulty because the reference to the Control you want to use is not returning the value you expect. That's another question. This one assumes you have the value available.

Now, as far as I can see, you have not shared with us the name of the hidden TextBox you keep referring to. Fine. Unhelpful, but we can handle that. Twinny has used Me.txtBoxName whereas I just used SubFormname. If you need more specific help than that then you really need to start focusing a bit more on giving information rather than just getting it. We try with our hands tied, but just remember who tied them.

Having said all that, I get the strong impression you're trying to be as responsive as you can be. That's always most important.

As a last attempt to give you something you can use I will first explain that you need to update this based on whatever name you've used for the TextBox Control you need to use from your own Form.
Expand|Select|Wrap|Line Numbers
  1. Forms("MainForm").Controls(Me.YourTextBox).Requery
So, replace Me.YourTextBox with a reference to your own TextBox. Typically that should start with Me.txt... but that's just good advice and not mandatory. Quotes are not required here as you are referring to a Control on your Form.

If your Control is not returning the value you expect then, obviously, you need to fix that problem before testing this solution. Clearly it will not work unless the basic framework you described originally can be relied on.
Jan 26 '19 #15
twinnyfo
3,653 Expert Mod 2GB
PrivateGuy,

Did NeoPa's solution work for you? I received an error when I referred to the Controls....

I have just tested the following syntax and it does, in fact, requery the referred subform:

Expand|Select|Wrap|Line Numbers
  1. Forms!frmMainForm.Form(Me.txtFormName).Requery
Replace frmMainForm with the actual name of the main form to which you are referring.

Replace txtFormName with the actual name of the control that holds the name of the subform you want to requery.

Hope this hepps!
Jan 26 '19 #16
privateguy
15 Byte
Twinnyfo,

Yes. The structure of NeoPa's syntax as well as yours worked without error! Two different ways of accomplishing the same task. In analyzing them, I see the distinct value of both. For brevity, I like using the ! mark instead of having write out the word Controls.

I give kudos to both you and NeoPa. I say to both of you that I am very appreciative of your expertise in helping me solve this problem. I humbly thank you.
Jan 27 '19 #17
twinnyfo
3,653 Expert Mod 2GB
Glad we could be of service. referring to objects can be a bit confusing at times, but once you figure it out, it can be very flexible.

Cheers!
Jan 27 '19 #18
NeoPa
32,556 Expert Mod 16PB
PrivateGuy:
Yes. The structure of NeoPa's syntax as well as yours worked without error! Two different ways of accomplishing the same task.
That's not quite accurate, I'm afraid. There is a very real difference. It's all explained in Referring to Items on a Sub-Form but let me see if I can highlight the difference here.

Say I have a Form, frmA, which has a TextBox Control, txtB, as well as three Sub-Form Controls (sfm1, sfm2 & sfm3) on it. Now, I can reference sfm2 from anywhere as either Forms!frmA!sfm2 or Forms("frmA").Controls("sfm2").

However, as I have three such Subform Controls on the Form it turns out I want to use whatever's in txtB to determine which of the Subforms I want to reference. I can do that using (Always assuming the TextBox has a value that matches the name of one of the Subform Controls.) :
Expand|Select|Wrap|Line Numbers
  1. Forms!frmA.Controls(Forms!frmA!txtB)
However, I can't do that using the ! syntax exclusively. The following :
Expand|Select|Wrap|Line Numbers
  1. Forms!frmA!txtB
simply references the TextBox Control itself, rather than the Subform whose name is the .Value of that TextBox Control.

So, yes, the ! format can be used as a shortcut. But!! It always helps to understand fully what it's doing. If that understanding is lacking then it won't behave as expected.
Jan 28 '19 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bruce W...1 | last post by:
My PHP html file includes a header include, a form, and a footer include. After the user submits their information I want to replace the form part of the page with a thank you note. All the...
1
by: Jurij P | last post by:
I have a problem. I would like to change a value from textbox with JavaScript before I submit the form (submit updated value). Can anyone please help me? thank you, Jure
0
by: Luis Esteban Valencia | last post by:
am trying to databind within an asp:textbox control. I have tried many variations found here but nothing seems to work. It works fine if I use a regular HTML textbox input though. Here is what I...
3
by: VB Programmer | last post by:
In my ASPX page how do I get the .text value of a textbox that is in the ItemTemplate of a datalist (using HTML)? The textbox contains the quantity for a shopping cart item. The textbox is...
8
by: Dean Slindee | last post by:
I have a form whose Property value I need to get at from a class (contained in another project, same solution). Here is the form's property: Private booIsInsert As Boolean = False Public...
17
by: alxasa | last post by:
Hi, can someone please show me how to most elegently do this?..... I have a textbox, and I want to search the contents of it and replace all instances of a certain word, and replace that word...
1
by: mark | last post by:
Forgive me if this seems like a stupid question but I need help... I'm trying to do a simple online form that emails me the results from a few fields. Here is the code: <form...
1
by: phpmel | last post by:
Hi guys, I wanted to set the value of a textbox to be the username of whoever is logged into my application. In the login page, a session variable username was set to be the username of whoever...
1
by: Andrus | last post by:
I need to create legal file name form any string so that PDF and other viewers show nice title. I created method LegalFileName() which uses 2 helper methods. It replaces <>\/:?*"| characters in...
0
by: jtjohnston | last post by:
Here is a definitive working answer. Does anyone have another? I asked a question here once and got an answer. This time, I thought I would bring an answer to a question that has been annoying me for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.