How can I obtain the name of the current control in a form.
I have a form which calls form 2. From form 2, I need the name of the control from form 1 which called form 2.
You could use the OpenArgs portion of the Docmd.OpenForm event to pass the name of the control (or any other info) to the 2nd form. Then in the OnOpen of Form2, you'd put something like:
If Me.OpenArgs = "ControlName" then
Blah1
Else
Blah2
End if
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
Hi
I am passing in the name of the control via OpenArgs to form2. What I want to accomplish is (I test for a certain condition in form2) if that condition is true, then I want to unselect the checkbox in form 1.
I am passing in the name of the checkbox, but the problem is, I have 25 checkboxes on form 1 that can call form 2.
I don't want to write all those if statements...
Forms!frmAccountDev!chkBox1 .... chkBox25
I want forms!frmAccountDev!Value passed in from OpenArgs
You want to pass the VALUE of the check box on Form 1 to Form 2.
On Form 2 you are doing some kind of computing which decides if the check box on Form 1 should be unchecked or not.
Is that correct?
If so, I have a question:
What computing are you doing on Form2 that you cannot do on Form1?
Also, will you be pushing the button 25 times?
Maybe if you post some more details, like the code and processing details on Form 2, we can find a better solution for you.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244. Basics at
Thanks for you help.
You are correct, I am doing some computing on form 2, and I am not pushing the button 25 times. There are 25 check boxes on form 1 that may or may not be clicked. Most times only a few might be clicked.
Here's the code.
The key line is... Forms!frmAccountDev!chkIncumbency_F = 0
Since I am passing in the name chkIncumbency_F.Name in OpenArgs, I was hoping I could generically use that value kind of like this...
Forms!frmAccountDev!ValuePassedIN = 0
On Error GoTo err_sub
Dim sSQL As String
Dim db As Database, strv As String
If MsgBox("Delete this record?", vbOKCancel) = vbOK Then
Set db = CurrentDb
sSQL = "DELETE * FROM [Issues] WHERE LinkID = " & Me.txtLinkID.Value & " AND DocumentLabelName='" & Me.txtDocument.Value & "'"
db.Execute sSQL
iTotal = CountIssues(Me.txtLinkID, Me.txtDocument)
If iTotal = 0 Then
Forms!frmAccountDev!chkIncumbency_F = 0
End If
End If
DoCmd.Close
End If
(At least) Two questions re communication between forms. Mayhap they are related? If so, the questions might be quite a bit easier to answer if the overall situation were in a single thread.
On the otherhand, I'll take a QUICK stab at an approach.
To be able to references any / all controls on a form, all you need is a reference to the form. so, asuming that "Form1" is the first object and "Form2" is the second one. Send some information to Form2 in its open arg(s). It could be the Form, or one of the controls, although the technique for dealing with the controls on Form1 (from Form2) will vary slightly and it is a lot easier if the type of the argument is known at design time. For the moment, assume that you instantiate Form2 from Form1 with a single value in the OpenArgs, as a name of the form itself. Assuming Form2 in instantiated with the standard DoCmd.OpenForm "Form2", OpenArgs: = Me.Name
Form2 can immediatly reference the form itself as ComesFrom = Forms(OpenArgs).Name (or in the immediate window - ? Forms(OpenArgs).Name which returns the NAME of Form1. Further, it is now apparent that the controls of Form1 can also be references as in ? Forms(OpenArgs).Controls.Count, and a simple loop could be used to enumerate the controls them selves, and their properties and values. Thus, the prudent user having used a reasonable naming convention is easily able to discern the check boxes from the label (and other controls simply using theur name property (whilst - of course the lazy and hurried programmer must wend their way a level or so deeper investigating the ControlType property - but that belongs to another discussion). Thus being able to discern the controls of interest, their values are correspondingly just their default property.
Alternativly, the control NAME is passed in a similar manner. The use of the controls's PARENT property returns the form name and the remainder of the controls and their properties are available as noted above.
OK I got it. Thanks to all. I was on the right track, I did not know to put parens around the variable name to make act right. These are the things you don't find in books too easily.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.