473,414 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Me.txtControl.Text not producing the expected results in OnChange event

Seth Schrock
2,965 Expert 2GB
I have a search form with two unbound textboxes: txtFirst and txtLast. I use these to filter the results found in my subform. Both controls have the OnChange event that is very close, but slightly different from each other. Here is the OnChange event for txtFirst:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtFirst_Change()
  2.       Dim strFilter As String
  3.  
  4. 10    On Error GoTo Error_Handler
  5.  
  6. 20    With Me
  7. 30        If .txtFirst & "" = "" Then
  8. 40            strFilter = "CustFN Like '*' "
  9. 50        Else
  10. 60            strFilter = "CustFN Like '*" & .txtFirst.Text & "*' "
  11. 70        End If
  12.  
  13. 80        If .txtLast & "" = "" Then
  14. 90            strFilter = strFilter & "and CustLN Like '*'"
  15. 100       Else
  16. 110           strFilter = strFilter & "and CustLN Like '*" & .txtLast & "*'"
  17. 120       End If
  18.  
  19. 130   End With
  20.  
  21. 140   With Me.sfrmQuoteSearch.Form
  22. 150       .Filter = strFilter
  23. 160       .FilterOn = True
  24. 170       .Requery
  25. 180   End With
  26.  
  27. Exit_Procedure:
  28. 190       Exit Sub
  29.  
  30. Error_Handler:
  31. 200       Call ErrorMessage(Err.Number, Err.Description, "Form_frmQuoteSearch: txtFirst_Change")
  32.           'TSCs_ReportUnexpectedError "txtFirst_Change", "Form_frmQuoteSearch", "Custom info"
  33. 210       Resume Exit_Procedure
  34. 220       Resume
  35.  
  36. End Sub
Here is what I'm experiencing. When I open the form, I click inside txtFirst and start typing. However, there is no change to the data in the subform. I stepped through the code, and verified that even if I have typed "Test", the criteria string just has "*". I then tab to txtLast and start typing "Person". The code now sees the text in txtFirst, but not in txtLast. If I shift + tab or just click to go back to txtFirst, my changes are now seen as I change (as I would expect). I can then tab/click to txtLast and changes are seen as the change occurs. If I then close the form and start over, again I see the weird behavior of it not seeing the changes (although the OnChange event does trigger) the first time the control is entered.

The only difference between the two events is that txtLast references txtFirst without the .Text property and references itself with the .Text property.

What am I doing wrong?
Jul 1 '13 #1
6 1179
zmbd
5,501 Expert Mod 4TB
just because... insert a repaint as line 175, just to be sure the form has refreshed.
Jul 1 '13 #2
Seth Schrock
2,965 Expert 2GB
If I do a debug.print to test the value of strFilter, it doesn't change strFilter to add the new characters unless I have typed something into it, left the control, and then re-entered it. For example, lets assume that I'm trying to type my name into the fields. The results would be as follows:

Expand|Select|Wrap|Line Numbers
  1.  I enter txtFirst for the first time
  2. txtFirst Value      txtLast Value       Debug.Print result
  3. S                                       CustFN Like '*' AND CustLN Like '*'
  4. Se                                      CustFN LIke '*' AND CustLN Like '*'
  5.  
  6. I tab over to txtLast for the first time
  7. Se                  S                   CustFN Like '*Se*' AND CustLN Like '*'
  8. Se                  Sc                  CustFN Like '*Se*' AND CustLN Like '*'
  9.  
  10. I Shift+tab back to txtFirst (second time entering the control)
  11. Set                 Sc                  CustFN Like '*Set*' AND CustLN Like '*Sc*'
  12. Seth                Sc                  CustFN Like '*Seth*' AND CustLN Like '*Sc*'
  13.  
  14. I tab back to txtLast for the second time
  15. Seth                Sch                 CustFN Like '*Seth*' AND CustLN Like '*Sch*'
  16. Seth                Schr                CustFN Like '*Seth*' AND CustLN Like '*Schr*'
Because of these results, it doesn't matter if the subform requeries since the filter being added wouldn't change the records being shown while I'm tying in txtFirst for the first time. As soon as I start typing in txtLast, the txtFirst filter works, but not the last name filter. Once I switch back to txtFirst, then I start getting the results that I'm looking for.
Jul 2 '13 #3
zmbd
5,501 Expert Mod 4TB
As line 185, Insert DoEvents
http://bytes.com/topic/access/answer...shed-do-events
Jul 2 '13 #4
Seth Schrock
2,965 Expert 2GB
That didn't change anything.

Update to my testing. If I tab to txtLast and then shift+tab back without typing anything into txtLast, the filter still doesn't work.
Jul 2 '13 #5
zmbd
5,501 Expert Mod 4TB
Ok, enough with the new wheel...
Find as you type
Find as you type 2
Find as you type - Code

So reading thru this I have the old V8 (duhhhh-I-know-that-duhhh) moment
If the function was called from the text box, we must use its Text property, since its Value has not been updated yet.
Put a Stop as Line 15...
From a "fresh" open of the form... how is the code executing when you press a key... do several... I think at Line 30, the logic is true, so line 40.... change line 30 to look at the text property, same for the other simular references where you are looking for the change in the control. Until the textbox looses focus there's no update to the value property.
Jul 2 '13 #6
Seth Schrock
2,965 Expert 2GB
I just figured it out. I'm testing the value of .txtFirst instead of .txtFirst.Text. Duh. I got it correct that I needed to use the .text property when I was creating the filter, but not in the test.

Thanks for getting me to look at the code better Z.
Jul 3 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
2
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
1
by: MDBloemker | last post by:
can anyone help me fathom out how to use this bit of code: Public Class Utilities Public Shared Sub CreateConfirmBox(ByRef txt As WebControls.TextBox, _ ByVal strMessage As String)...
1
by: Chris Ashley | last post by:
I'm using the javascript onchange event in a few places but it's behaviour isn't as expected. In order for this event to fire after changing text in a textbox, the user needs to either tab out of...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
4
by: Dave | last post by:
I am having difficulty filtering a form as the user types in a onchange event here is my code strFilter = cboCriteria.Value & " LIKE '" & Me!txtCriteria.text & "*" & "'" If Len(strFilter ) 0...
18
by: Mike Will via WebmasterKB.com | last post by:
I need some help with an onchange event for one of my select boxes on my form. I need to select a value from the box and use that value in the query that will produce results for another select...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
1
by: jonnyothan | last post by:
The following code isn't producing expected results: class Selectable { bool IsSelected() const; }; class Unit : public Selectable { };
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.