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: - Private Sub txtFirst_Change()
-
Dim strFilter As String
-
-
10 On Error GoTo Error_Handler
-
-
20 With Me
-
30 If .txtFirst & "" = "" Then
-
40 strFilter = "CustFN Like '*' "
-
50 Else
-
60 strFilter = "CustFN Like '*" & .txtFirst.Text & "*' "
-
70 End If
-
-
80 If .txtLast & "" = "" Then
-
90 strFilter = strFilter & "and CustLN Like '*'"
-
100 Else
-
110 strFilter = strFilter & "and CustLN Like '*" & .txtLast & "*'"
-
120 End If
-
-
130 End With
-
-
140 With Me.sfrmQuoteSearch.Form
-
150 .Filter = strFilter
-
160 .FilterOn = True
-
170 .Requery
-
180 End With
-
-
Exit_Procedure:
-
190 Exit Sub
-
-
Error_Handler:
-
200 Call ErrorMessage(Err.Number, Err.Description, "Form_frmQuoteSearch: txtFirst_Change")
-
'TSCs_ReportUnexpectedError "txtFirst_Change", "Form_frmQuoteSearch", "Custom info"
-
210 Resume Exit_Procedure
-
220 Resume
-
-
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?
6 1179 zmbd 5,501
Expert Mod 4TB
just because... insert a repaint as line 175, just to be sure the form has refreshed.
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: - I enter txtFirst for the first time
-
txtFirst Value txtLast Value Debug.Print result
-
S CustFN Like '*' AND CustLN Like '*'
-
Se CustFN LIke '*' AND CustLN Like '*'
-
-
I tab over to txtLast for the first time
-
Se S CustFN Like '*Se*' AND CustLN Like '*'
-
Se Sc CustFN Like '*Se*' AND CustLN Like '*'
-
-
I Shift+tab back to txtFirst (second time entering the control)
-
Set Sc CustFN Like '*Set*' AND CustLN Like '*Sc*'
-
Seth Sc CustFN Like '*Seth*' AND CustLN Like '*Sc*'
-
-
I tab back to txtLast for the second time
-
Seth Sch CustFN Like '*Seth*' AND CustLN Like '*Sch*'
-
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.
zmbd 5,501
Expert Mod 4TB
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 ,...
|
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...
|
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)...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: jonnyothan |
last post by:
The following code isn't producing expected results:
class Selectable
{
bool IsSelected() const;
};
class Unit : public Selectable
{
};
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |