Connecting Tech Pros Worldwide Forums | Help | Site Map

Value of text box before it is saved

Newbie
 
Join Date: Jul 2008
Posts: 11
#1: 3 Weeks Ago
I have an unbound text box on an MS ACCESS 2000 form that has an imput mask set for short dates, i.e. 04/11/09. I have some code within the ON_CLICK event of this control that puts the curser at the front, left hand side, of the text box.

I only want this code to work if there is no value within the text box. It works fine when the textbox is empty and ignors the code as expected if I click on something else after adding a date and then click back into the textbox.

My problem is the textbox has no value if the user is currently typing something in for the first time. If the user is currently typing a date and wants to click on another part of the date to correct it the cursor is positioned at the front regardless of where the user clicked. Following is the code i'm using in the ON_CLICK event, any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. If IIf(IsNull(Me.ActiveControl), "", Trim(Me.ActiveControl)) = "" Then
  2.     Me.ActiveControl.SelStart = 0
  3. End If
best answer - posted by ChipR
You can use the textbox.Text property to get the currently contents.

Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,175
#2: 3 Weeks Ago

re: Value of text box before it is saved


You can use the textbox.Text property to get the currently contents.
Newbie
 
Join Date: Jul 2008
Posts: 11
#3: 3 Weeks Ago

re: Value of text box before it is saved


Many thanks for that ChipR. I guess one should not rely so heavily on autocomplete as Text is not one of the drop down options of ActiveControl but it does work. Thanks again, it works well.
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,175
#4: 3 Weeks Ago

re: Value of text box before it is saved


The reason it doesn't show up is probably because the property doesn't exist for every possible control that may be the ActiveControl. Be careful using it, you may want to test the type of the control first.
Reply