UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> GetCurrentControlValue    

Occassionally situations may arise where you want to capture the current text in a control, regardless of whether the control has the focus or not. If the control has the focus and is the appropriate control type, the Text property will yield the current control text if it has not yet been saved, otherwise the control's Value property must be read.

This function retreives the current value/text in a control regardless of the save status of the control. This is particularly useful when working with shortcut commands that may be dependant upon a control but without knowledge of it's save state.

The function requires the IsActiveControl function.

CODE

' GetCurrentControlValue
' http://www.utteraccess.com/wiki/index.php/GetCurrentControlValue
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2011-09-02
'
' Dependancies:
'   IsActiveControl: http://www.utteraccess.com/wiki/index.php/IsActiveControl
'
Public Function GetCurrentControlValue(ctl As Control) As Variant
 'retrieves the current commited or uncommited value of a control
 'If the control is active and of the right controltype, the
 'Text property will attempt to be read, otherwise the Value
 'property of the control will be returned. Intended for use
 'with the shortcutmenu callback in the instance where the
 'user may edit a control and rightclick/runshortcut before
 'the value is commited to the control.
 Dim ret As Variant
   
 'determine if the active control is the control we're working with
 'if so, we'll catch check to see if the Text property is available
 
 If Not IsActiveControl(ctl) Then
   'not active just get the value
   ret = ctl.Value
   
 Else
   'active, check the type and text if applicable
   If (ctl.ControlType = acTextBox) Or (ctl.ControlType = acComboBox) Then
     ret = ctl.text
   Else
     ret = ctl.Value
   End If
 End If
 
 GetCurrentControlValue = ret
 
End Function


Creative Commons License
GetCurrentControlValue by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 2,888 times.  This page was last modified 02:06, 4 September 2011 by Jack Leach.   Disclaimers