Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unbound Textbox Value 3

Status
Not open for further replies.

bcooler

Programmer
Jun 13, 2009
132
So, for all my ADHD friends, I'll ask the question first, then give all the boring details next....

Any ideas on how to force an unbound textbox's value to update each time I press a keyboard character?


Now the details....

I have an unbound textbox that I am using as entry for a Google-like search. This depends on resetting the form's filter after each keystroke. I've got it to work, but I'm frustrated at the band-aid I had to use and think there must be a better way.

When I enter info into the textbox and "watch" the textbox value during the textbox_change event, I see an unchanged value (textbox hasn't updated yet). I assumed the textbox doesn't assume a value until you leave the textbox, so I just set the focus on another object and then back onto the original textbox. At this point, the textbox does correctly show the info I entered.

Now, I have tried the .text version of the textbox value, but I must have focus to read it and that causes problems later.

Thanks!
 
Here is an example of an unbound txt box I use to do a form search on.The code is run after the update event.
Private Sub Combo202_AfterUpdate() 'updated 8/29/03

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[TimeID] = " & Str(Me![Combo202])
Me.Bookmark = rs.Bookmark
Me![Combo202] = Null
Me!Labelsearch.Visible = True

End Sub

 
Private Sub txtBx_Change()
Me.txtBx.Value = Me.txtBx.Text
End Sub
 
How are ya bcooler . . .

The post by MajP can solve the problem. However there's a small issue of selecting [blue]all the text[/blue] when the [blue].Value[/blue] is updated this way, (prevents continuous typing) ... 2003. Another line of code does the trick:
Code:
[blue]Private Sub txtBx_Change()
   Me.txtBx.Value = Me.txtBx.Text
   Me.txtBx.SelStart = Len(Me.txtBx.Value)
End Sub[/blue]
[blue]Your Thoughts . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank you TheAceMan1 for your help. I considered this also, but I discounted it because I assumed this would cause a repeating loop because this change would force the repeat of the change event?
 
bcooler . . .
bcooler said:
[blue] I considered this also, but [purple]I discounted it because I assumed this would cause a repeating loop[/purple] ...[/blue]
Your quote tells me you've never read the help on the [blue]Change[/blue] event:
Microsoft said:
[blue]The [purple]Change[/purple] event occurs when the contents of a textbox or the text portion of a combo box changes.[/blue]
So ... as long as data doesn't change ... recursion doesn't occur. Which means that setting where data entry occurs doesn't trigger the [blue]Change[/blue] event. Thats why ...
Code:
[blue]   Me.txtBx.SelStart = Len(Me.txtBx.Value)[/blue]
... works! ... there's no change of data!

You should give [blue]MajP[/blue] a star for insight into this!

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Excellent! Thank you for clearing up my ignorance. I am always very appreciative of websites like this where people take time from their busy lives to help others. God bless!
 
bcooler . . .

Because I consider you to be worthy ... I'd like to introduce you to something in Access called [blue]Context Sensitive Help[/blue] (aka ... finding info in help). Instead of explaining it, I'll give you instances of using it. Its something you'll never forget!
[ol][li] While programming in a module ... type the word of something you need to know about ... [blue]put the cursor within the word[/blue] and hit [blue]F1[/blue]!. If Access has it, it'll come up with the info.[/li]
[li]If you need to know about a property or event, put the cursor on the line and hit [blue]F1[/blue]![/li][/ol]
Access help might not be that great, but [blue]Context Sensitive Help[/blue] is! ... Use it well! ...

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank you! I do use that often, but missed it on this occasion.

However, where I do have inefficiencies is the effective use of the following. Perhaps you know of a good source to explain?

Intermediate window
Locals Window
Object Browser

The last one is of most interest. I believe that many are in the same camp as myself (interested to use Access, but inexperienced to know all the functionality. This forces me to Google for solutions instead of having a "dictionary" to explain all my VBA options).

Thanks!
 
bcooler . . .

Didn't forget you. In my years I've made unprecedented use of the [blue]Immediate & Watch[/blue] windows. These two windows will be of more help to you than any others ... particularly as troubleshooting aids. Here's a few references:

Using the Immediate Window

The Watch Window

The Object Browser

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top