Enter key enters current time then moves to next field

C

crtopher

have a series of fields that record a series of times. On my form I'd like
each field in succession to have the current time entered into it and then
move to the next field all with a simple press of the enter button.

Currently i have a button on the form labelled "now" that enters the current
time in whatever field i have the cursor in using the following code:

Application.Screen.PreviousControl.SetFocus
Me.ActiveControl = Time()

This works well. I have even set its default to "yes" so that when i hit
'enter' the current time is recorded. The problem is that even though i have
the enter key behaviour set to go to the next field via the menu option, it
wont do it when the buttons default is set to yes.

Do i need another line in my code to force the next control to get the focus?

I have read all the forums about changing enter key behaviour as well as
ansi code for the key press event but cant seem to do what i need to do.

Thanks in advance
 
S

Stuart McCall

crtopher said:
have a series of fields that record a series of times. On my form I'd like
each field in succession to have the current time entered into it and then
move to the next field all with a simple press of the enter button.

Currently i have a button on the form labelled "now" that enters the
current
time in whatever field i have the cursor in using the following code:

Application.Screen.PreviousControl.SetFocus
Me.ActiveControl = Time()

This works well. I have even set its default to "yes" so that when i hit
'enter' the current time is recorded. The problem is that even though i
have
the enter key behaviour set to go to the next field via the menu option,
it
wont do it when the buttons default is set to yes.

Do i need another line in my code to force the next control to get the
focus?

I have read all the forums about changing enter key behaviour as well as
ansi code for the key press event but cant seem to do what i need to do.

Thanks in advance

You could try:

Application.Screen.PreviousControl = Time()

I'm a little baffled by your statement "I have even set its default to
"yes". Is this textbox supposed to hold a date value or a string ("yes") ?
 
L

Linq Adams via AccessMonster.com

He's saying that he's set the Default Property of the command button to Yes,
so that anytime he presses <Enter> it's the same as pressing the command
button. That's the reason hitting <Enter> doesn't move to the next control.
It can only do one thing, if it fired the command button, it can't advance
the cursor.

Try this code, crtopher:

Private Sub txtTextBoxName_GotFocus()
If IsNull(Me.txtTExtBoxName) Then
Me.txtTExtBoxName = Time
End If
End Sub

This will only place the Time in the textbox if it is currently empty. If
your needs require that the current time be placed in it each time the user
enters the texbox, simply use

Private Sub txtTextBoxName_GotFocus()
Me.txtTExtBoxName = Time
End Sub
 
S

Stuart McCall

Linq Adams via AccessMonster.com said:
He's saying that he's set the Default Property of the command button to
Yes,
so that anytime he presses <Enter> it's the same as pressing the command
button. That's the reason hitting <Enter> doesn't move to the next
control.
It can only do one thing, if it fired the command button, it can't advance
the cursor.
<snip>

OIC. I had Default value in mind <slaps forehead>. Thanks.
 
L

Linq Adams via AccessMonster.com

Forgot to add, change the the Default Property of the command button to No,
or simply delete the command button if no longer needed.

BTW, Access actually has keyboard shortcut for doing this

<Ctrl> + <Shift> + <:>

will place the current time in a textbox..
 
C

crtopher

Hi Stuart and Ling...thank you so much for your reply...i have been away for
a few days hence my "radio" silence. I will try your suggestion Ling and get
back to you

Cheers
Chris
 
C

crtopher

Hi Ling ...

My form is all about real time entry of event times...ie events happen, the
person with the form is sitting there waiting to enter the time as it
happens. Intuitively you would place your cursor in the text box, wait for
the event, hit the key, and as a nice touch the cursor would move to the next
box waiting for the next time entry.

By putting commands on the on the OnGotFocus and OnLostFocus events, which
I've tried, the user has less control over the entry ie every time he/she
moves in or out of the field the time is changed rather than only when he/she
determines by the press of a button.

The key combo of "ctrl shift :" is kind of the idea but i want it to happen
with one key press ideally and for the focus to shift to the next control.

Maybe I want too much!

Anyway, all ideas gratefully appreciated!

CHeers
Chris
 
J

John W. Vinson

The key combo of "ctrl shift :" is kind of the idea but i want it to happen
with one key press ideally and for the focus to shift to the next control.

Maybe I want too much!

Anyway, all ideas gratefully appreciated!

What I'll often use to record times (for example in a dispatching application
I've built) is to set the textbox's value to Now in its Doubleclick event.
Click is too "hair trigger" in practice (fires when you try to set focus to
the box for example), but doubleclick is something that is easy to do when you
INTEND to do it. You can setfocus to some other control immediately if you so
desire:

Private Sub txtEventTime_DoubleClick()
Me!txtEventTime = Now
Me!nextcontrolname.SetFocus
End Sub
 

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