473,503 Members | 3,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing a form using a variable for the form name

9 New Member
I have a Function in a Module that takes in a parameter. From my form, I call that function and pass my form name. I'm trying to use forms!formname.Controls in the function and I get the error:

Access can't find the form 'FormName' reffered to in macro express of vb code

The code in the form that calls the function is:
Check_Req_Fields "tbAddDocument"
And the code in the function:

Function Check_Req_Fields(FormName As String)

For Each ctrl In Forms!FormName.Controls
If TypeName(ctrl) = "TextBox" Then
If ((IsNull(ctrl.Value)) Or ctrl.Value = "") And (ctrl.Tag = "req") Then
err = err + 1
MsgBox "Please enter a value for " & ctrl.Name
Exit For
End If
End If
Next ctrl


Thank You
Nov 4 '08 #1
2 5103
Stewart Ross
2,545 Recognized Expert Moderator Specialist
There is an error in the way you are accessing the forms collection - it should be Forms(formname) to use the value of your formname variable, not
forms!formname, which will try to access a (nonexistent) form called formname. The variable's value cannot be substituted for the name of the variable when referring to forms using the ! notation.

-Stewart
Nov 4 '08 #2
ejamnadas
9 New Member
Thank you for pointing that out Steve. I do appreciate it.

Elesh
Nov 5 '08 #3

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

Similar topics

6
11267
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
5
1793
by: Amelyan | last post by:
I am struggling here trying to determine what is a good programming practice as far as referencing your URLs. When you use Response.Redirect, do you use 1) Hard-coded string --...
2
1587
by: mdiddy | last post by:
I'm learning vb, coming from a Perl background. I want to know how to reference a form element by using a counter variable in the element's name. For instance, let's say I have a form with 10...
6
2733
by: Mat | last post by:
Dear all, What I want to do is be able to use a string to refer to a control on a subform. IE: Forms!("Form1!form2!controlA").name or
3
1397
by: libsfan01 | last post by:
Hi all whats wrong with this script? i have named a form text box dynamically using php each row has a textbox called q101, q102 ... etc and i want to make sure my users dont input a quantity...
21
5065
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
2
1428
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
3
3943
by: rls03 | last post by:
I have the following which creates a variable containing a relative path where <xsl:value-of select="."/returns a portion of the filename: <xsl:variable...
5
2080
by: Diego Pino | last post by:
Hello, I am experience some problems reading a form variable from a Javascript function. The point with this particular variable is that its name has the following syntax: <input...
0
7261
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
7315
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...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.