G
Guest
I have a function in which I move through all the controls in an Access 2002
form. When I get to a control whose tag matches an argument (strTag), I want
the function to return the control. The problem is that after the 'Next'
statement, my element variable, cntX, gets reset to Null. However, the
function will still be able to find a match in the control's tag, but the
function returns Null.
The code is below.
***********************
* Private Function ControlFromTag(ByRef strTag As String) As Control
* 5: 'Finds a control that has the specified tag and returns the control
*
* 10: Dim cntX As Access.Control 'Declare Access control.
* 20: For Each cntX In Me.Controls 'Move to each control in collection
(an Access form).
* 30: If cntX.Tag = strTag Then 'Check to see if the control's tag
matches the argument.
* 40: Set ControlFromTag = cntX 'Match found, set function equal to
found control.
* 50: Exit Function
* 60: Else
* 70: End If
* 80: Next cntX 'Move to next control in collection. cntX set to Null
after first time Line #80 executes. Why??
* 90: Set cntX = Nothing 'Destroy object.
* 100: End Function
***********************
Any help would be very appreciated.
Thanks,
Eric
form. When I get to a control whose tag matches an argument (strTag), I want
the function to return the control. The problem is that after the 'Next'
statement, my element variable, cntX, gets reset to Null. However, the
function will still be able to find a match in the control's tag, but the
function returns Null.
The code is below.
***********************
* Private Function ControlFromTag(ByRef strTag As String) As Control
* 5: 'Finds a control that has the specified tag and returns the control
*
* 10: Dim cntX As Access.Control 'Declare Access control.
* 20: For Each cntX In Me.Controls 'Move to each control in collection
(an Access form).
* 30: If cntX.Tag = strTag Then 'Check to see if the control's tag
matches the argument.
* 40: Set ControlFromTag = cntX 'Match found, set function equal to
found control.
* 50: Exit Function
* 60: Else
* 70: End If
* 80: Next cntX 'Move to next control in collection. cntX set to Null
after first time Line #80 executes. Why??
* 90: Set cntX = Nothing 'Destroy object.
* 100: End Function
***********************
Any help would be very appreciated.
Thanks,
Eric