Events Question

suburbanpsyco

Registered User.
Local time
Today, 14:40
Joined
Apr 18, 2011
Messages
19
General question about how to get an event to work. I have the following simple code.

Code:
If RegexMatch(Me.txtSearch.Value) Then
        rstReportGenerator.MoveFirst
        rstReportGenerator.Find "partNumber >= #" & Me.txtSearch.Value & "#"
        If rstReportGenerator.EOF Then
            rstReportGenerator.MoveLast
        End If
        Me.lstParts.Value = rstReportGenerator!partNumber
End If

It is currently coded behind a button. Works like a charm. Now when i try to move this to the KeyPress event i get: Invalid use of null, on the first line. (If RegexMatch(Me.txtSearch.Value) Then) At first i thought this was just when the original value of the textbox is nothing, but even when there is a value in the box on form load, the same error is given.

Any insight? Thanks in advance
 
The On Key Press event may not be where you want your code. This event occurs every time a key is pressed. From looking at your code, it would appear that you need this action to only occur when you have entered a value in your textbox. If this is the case try placing your the AfterUpdate event of your textbox. If this is not the case, please explain a little more about just when you want this to happen.
 
Thanks for the reply.

I am trying to run this event for every new character the user enters into the text field. For example:

type s - search would return sam
type y - search now returns synergy
delete y - search returns sam again

i thought the key press would be the correct event for this, since it would fire every time the user presses a key, but only when the textbox has focus.

Hope this helps.


EDIT: Ive managed to tweak the afterUpdate event to work, But id still like the event to fire as the user is typing. There is a specific purpose why i need this, and given the fact it is tied up in a lot of upper management BS, im not going to bore you with the details :D
P.S. Tried working with the afterUpdate event as well. the event does not fire at all
 
Last edited:
I would recommend using the Change event and the Text property of the textbox control. Consider the code...
Code:
Private Sub MyTextbox_Change()
  debug.print "Changed: ",
[COLOR="Green"]  '.Value property is not updated until the AfterUpdate event[/COLOR]
  debug.print " value = " & me.mytextbox.value,
[COLOR="Green"]  '.Text property is available during the change event and when the control has the focus[/COLOR]
  debug.print " text = " & me.mytextbox.text
End Sub
Cheers,
Mark
 
Brilliant mark, but that only seems to work in one direction! As soon as i delete an item, the event stops working altogether, i am currently fiddling with this code trying to get it to co-operate, but this certiainly seems a step in the right direction! Kudos!

P.S. While we are on this topic, an ideas why the event stops firing after a delete? I know for KeyPress event the Del key does not work, but i am using backspace in the Changed event & the KeyPress event.

EDIT: Thanks, managed to fix it by adjusting the name of the properties of the textbox slightly. Thanks Again!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom