Textbox After Update Event

A

alex

I have a form with a textbox linked to public dcount function that
returns a byte.

The function and textbox seem to work just fine; i.e., the textbox
returns the correct value and changes when it’s supposed to.

I’ve been trying to code the after update event of the textbox,
however, and can’t get it to fire. It just doesn’t recognize when
it’s updated.

What I’m looking to do should be incredibly simple: I’m trying to
hide the textbox if the value is 0.

I’ve tried several different types of code, but here’s my latest code
to see if I can get the thing to fire:

Private Sub txtIndicatorLight_afterupdate()

If Me.txtIndicatorLight.value > 0 Then ‘I’ve tried me.txtIndicator > 0
Me.txtIndicatorLight.visible = True
Else
Me.txtIndicatorLight.visible = False
End If

End Sub

Thanks,
alex
 
D

Dorian

That's a very weird thing you are trying to do and I am wondering why?
If someone types 0 by mistake and you hide the textbox, how will they ever
make a correction?
Try using the Change event, it fires for every character entered in the text
box.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
D

Douglas J. Steele

Unfortunately, even if that code were firing, it wouldn't work: you cannot
change the Visible property of a control that has focus. You'll have to set
focus to some other control first:

Private Sub txtIndicatorLight_AfterUpdate()

Me.SomeOtherControl.SetFocus
Me.txtIndicatorLight.Visible = (Me.txtIndicatorLight > 0)

End Sub

Are you saying, though, that the ControlSource of txtIndicatorLight is a
DCount statement? The AfterUpdate event only fires when you type something
into the textbox. You'll have to find some other way of causing the code to
run.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a form with a textbox linked to public dcount function that
returns a byte.

The function and textbox seem to work just fine; i.e., the textbox
returns the correct value and changes when it’s supposed to.

I’ve been trying to code the after update event of the textbox,
however, and can’t get it to fire. It just doesn’t recognize when
it’s updated.

What I’m looking to do should be incredibly simple: I’m trying to
hide the textbox if the value is 0.

I’ve tried several different types of code, but here’s my latest code
to see if I can get the thing to fire:

Private Sub txtIndicatorLight_afterupdate()

If Me.txtIndicatorLight.value > 0 Then ‘I’ve tried me.txtIndicator > 0
Me.txtIndicatorLight.visible = True
Else
Me.txtIndicatorLight.visible = False
End If

End Sub

Thanks,
alex
 
A

alex

That's a very weird thing you are trying to do and I am wondering why?
If someone types 0 by mistake and you hide the textbox, how will they ever
make a correction?
Try using the Change event, it fires for every character entered in the text
box.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".













- Show quoted text -

Thanks Dorian for responding...
Nobody types anything into the textbox; it's based on a function that
searches a table for records and it's locked. I've tried the on
change event. It too is not working.
alex
 
A

alex

Unfortunately, even if that code were firing, it wouldn't work: you cannot
change the Visible property of a control that has focus. You'll have to set
focus to some other control first:

Private Sub txtIndicatorLight_AfterUpdate()

  Me.SomeOtherControl.SetFocus
  Me.txtIndicatorLight.Visible = (Me.txtIndicatorLight > 0)

End Sub

Are you saying, though, that the ControlSource of txtIndicatorLight is a
DCount statement? The AfterUpdate event only fires when you type something
into the textbox. You'll have to find some other way of causing the code to
run.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)


I have a form with a textbox linked to public dcount function that
returns a byte.

The function and textbox seem to work just fine; i.e., the textbox
returns the correct value and changes when it’s supposed to.

I’ve been trying to code the after update event of the textbox,
however, and can’t get it to fire.  It just doesn’t recognize when
it’s updated.

What I’m looking to do should be incredibly simple:  I’m trying to
hide the textbox if the value is 0.

I’ve tried several different types of code, but here’s my latest code
to see if I can get the thing to fire:

Private Sub txtIndicatorLight_afterupdate()

If Me.txtIndicatorLight.value > 0 Then ‘I’ve tried me.txtIndicator > 0
Me.txtIndicatorLight.visible = True
Else
Me.txtIndicatorLight.visible = False
End If

End Sub

Thanks,
alex

Doug,
I guess you answered my question. I thought that the after update
event would fire regardless of how the value got there. I'll try to
run the code some other way. Thanks!
alex
 
B

Bob Quintal

:
Thanks Dorian for responding...
Nobody types anything into the textbox; it's based on a function
that searches a table for records and it's locked. I've tried the
on change event. It too is not working.
alex
Textbox events only fire when the data is modified via the user
interface.
No textbox events will fire when the data in the textbox is updated
from code.

Therefore, you need to find a reliable trigger for hiding the
textbox.
Could it be whatefer fires the function?
Could it be moving onto a new record.
Could it be after updating a different textbox?

If you explain a little about what causes the recalculation, we could
suggest the best place(s) to trigger the visibility change.
 
A

alex

Textbox events only fire when the data is modified via the user
interface.
No textbox events will fire when the data in the textbox is updated
from code.

Therefore, you need to find a reliable trigger for hiding the
textbox.
Could it be whatefer fires the function?
Could it be moving onto a new record.
Could it be after updating a different textbox?

If you explain a little about what causes the recalculation, we could
suggest the best place(s) to trigger the visibility change.

Thanks for the help Bob.
I added the code to the on close event of the pop up form that changes
the value of the public function. Everything seems to be working OK.
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top