Input not seen as value before pressing enter-key

Stefan.Kauw

Registered User.
Local time
Today, 16:42
Joined
May 31, 2018
Messages
24
When i enter a value in a textbox, this value isn't instantly available in VBA as a value. If i set focus to another textbox by clicking in it and want to msgbox the input of the textbox i get the error "Unvalid use of null".

I DO have to press enter to somehow acknowledge the value inside the textbox. How do i prevent that?

Something like... When losing focus, the input in the textbox is the value of the textbox.
 
remove the textbox and add new one.
or create new form.
 
In that case, in the textbook after update event, set a variable equal to the textbox value. Use the variable in your message box
 
In that case, in the textbook after update event, set a variable equal to the textbox value. Use the variable in your message box

I was thinking about that already but why is it that i have to do it this was?
There must be an explanation, right?
 
Not 100% sure of the scenario, but a few things come to mind:

Before the control updates, you need to read the .Text property of it (IIRC), rather than the .Value property. Maybe try that.

Also, many people reference the control itself, which usually resolves to the .Value property. Try being explicit. Instead of:

Me.MyControl, use Me.MyControl.Value (or, if appropriate, Me.MyControl.Text)

Not sure any of these will take care of the issue, but maybe worth noting...

Cheers
 
I was thinking about that already but why is it that i have to do it this was?
There must be an explanation, right?

@Stefan
I've just tested this and whilst it would work, it's not necessary to use a variable after all
No need for an after update event either

@jleach
It works equally well using MsgBox Me.Text0.Value or just MsgBox Me.Text0
However if you use MsgBox Me.Text0.Text as you suggested, error 2185 occurs (control focus error)

See attached db
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom