HELP : Using a string to create a reference to Form Controls 
Author Message
 HELP : Using a string to create a reference to Form Controls

Mark,
Unfortunately, you have to write a helper function to get a reference to a
control by name.  Here's an example:

Private Function GetControlFromName(ByVal ControlName As String) As Control
        Dim tempControl As Control
        For Each tempControl In Me.Controls
            If tempControl.Name = ControlName Then
                Return tempControl
            End If
        Next
End Function

Steve
VB.Net

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I've been trying to find a method to turn a string into a form control
> reference. So far, I can only use a control's index number to gain an
object
> reference to it.
> For instance

> 'This is all I've been able to accomplish...
> Dim chk As Checkbox
> chk = Me.Controls(1)

> 'This is what I'd like to be able to do ...
> Dim chk As Checkbox
> chk = Me.Controls("chkStatus") '<- It would be nice to get this to work
some
> how!

> Any ideas on how to get this to work??? Thanks

> Mark




Sat, 29 Jan 2005 03:53:16 GMT  
 HELP : Using a string to create a reference to Form Controls
Thanks. I've aready written a recursive function that crawls a form for
both parent containers and their respective children. I was kind of
hoping that MS would incorporate the ability to index controls via a
string reference but alas, no. What really through me for a loop was the
fact that you no longer can iterate through all the controls in a form
unless you write a recursive function.

I'm sure you're aware of the parent container issues with things like
tab controls and group boxes. A couple of other MS employees provided
some code, although, I had already written a class to handel it. Thanks
anyway.

Mark

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 29 Jan 2005 06:50:45 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How do I reference a form I've created from another form using VBScript

2. referencing object (form, report) using string variable

3. Need to load a form using string variable as reference

4. Create custom control in form using code (code wizard adding ocx to form)

5. Forms Collection: Using it to Open Forms by Passing the Form Name as a String Variable

6. File Type syntax using a string to create entry HELP

7. how to handle NULL values from a FORM when using date string functions - help please

8. Newbie: Help with the Data Control, or help creating Alternatives to using it

9. how to handle NULL values from a FORM when using date string functions - help please

10. Make a reference to a MDI form with a reference of a MDI child form

11. Create Validation Rule for Form Control using VBA or Macro

12. referencing a control on a caller form from the called form

 

 
Powered by phpBB® Forum Software