How to get the cursor back to the TxtBox?

J

Jeff

Hi Everyone,

I write a Public Function to check my input TxtBoxes in order to prevent
input error. I put this check in the AfterUpdate event of the TxtBox. When an
error is found and exit function, the cursor jumps to the next object in the
form, my problem is how to get the cursor back to that TxtBox?
 
G

Gijs Beukenoot

Jeff was zeer hard aan het denken :
Hi Everyone,

I write a Public Function to check my input TxtBoxes in order to prevent
input error. I put this check in the AfterUpdate event of the TxtBox. When an
error is found and exit function, the cursor jumps to the next object in the
form, my problem is how to get the cursor back to that TxtBox?

<object>.setfocus
 
M

Marshall Barton

Jeff said:
I write a Public Function to check my input TxtBoxes in order to prevent
input error. I put this check in the AfterUpdate event of the TxtBox. When an
error is found and exit function, the cursor jumps to the next object in the
form, my problem is how to get the cursor back to that TxtBox?


Use the BeforeUpdate event to verify the data before it
becomes the control's value. BeforeUpdate even has a Cancel
argument that will also prevent the focus from moving.
 
J

Jeff

Dear Gijs,

Because this is a Public Function, there are many TxtBoxes will refer to it.
Therefore, the TxtBoxes' names will be different. I don't know what I should
put for the <object> in <object>.SetFocus?

Jeff

"Gijs Beukenoot" 來函:
 
J

Jeff

Dear Marshall,

I have tried to put this check by referring to the Public Function with
Cancel = True if error is found in the BeforeUpdate event, but the cursor
still jumps to the next control. If I put If Error is found Then Cancel =
True & End If directly in the BeforeUpdate event, it works. What I want to do
is write a perfect Public Function and just simply refer to it every time I
need it. Can you tell me more?

"Marshall Barton" 來函:
 
G

Gijs Beukenoot

Jeff stelde de volgende uitleg voor :
Dear Marshall,

I have tried to put this check by referring to the Public Function with
Cancel = True if error is found in the BeforeUpdate event, but the cursor
still jumps to the next control. If I put If Error is found Then Cancel =
True & End If directly in the BeforeUpdate event, it works. What I want to do
is write a perfect Public Function and just simply refer to it every time I
need it. Can you tell me more?

"Marshall Barton" ��H

You're usinga macro now? Switch to VB-code for that property. Select
before-update, press the three dots at the end, choose program (or VBA
(I have a localized version so I'm not sure what it's called in
English)) and then, in that code, type
Cancel = (Not <your function>)
Your function should return TRUE when the data is correct...
 
J

Jeff

Dear Gijs,

I finally solve my problem, Thank you very much.

Jeff

"Gijs Beukenoot" 來函:
 

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