Keeping focus on a text box

G

Guest

I have a form on which I'm using my own record selector buttons to move
between records. I'd like to use some code to keep focus on a particular
text box (ItemNum) when moving between records if ItemNum had the focus prior
to moving to the next record. ItemNum is not the default 1st Text box on the
form. Any suggestions?

Thanks

Kevin D
 
S

Storrboy

Kevin D. said:
I have a form on which I'm using my own record selector buttons to move
between records. I'd like to use some code to keep focus on a particular
text box (ItemNum) when moving between records if ItemNum had the focus prior
to moving to the next record. ItemNum is not the default 1st Text box on the
form. Any suggestions?

Thanks

Kevin D


If ItemNum is always the one to move focus to, then in the Forms OnCurrent
event just use Me!ItemNum.SetFocus. If you want to move to the last control
to have focus, that may be a little trickier.
 
G

Guest

I want to move to the last control to have the focus if the last control was
ItemNum, otherwise to the default control.

Kevin D
 
S

Storrboy

Kevin D. said:
I want to move to the last control to have the focus if the last control was
ItemNum, otherwise to the default control.

Kevin D

"Storrboy" wrote:


I think I'm half asleep today. I've missed or misread a great many things
today.
Before you do your navigation code, store the name of the last control to
have the focus by setting a form public variable to
Screen.PreviousControl.Name. If no other controls have had focus, then an
error will occur, so be sure to allow the code to continue if one occurs.
Example

'In the declaration section of form module
'-------------------------------------------
Dim strContrlName As String

'Before navigation code in button
'-------------------------------------------
On Error Resume Next
strControlName = Screen.PreviousControl.Name
If Err <> 0 Then strControlName = ""


In the OnCurrent event of the form (so that for each change in record
position this will fire) check the variable and move to the desired control.
I don't know what you mean by the "default control" as when using the
built-in nav buttons, the focus stays with the one that had it last - so you
may need to specify which is the "default"

If strControlName <> "ItemNum" Then strControlName = "[DefaultControlName]"
Me.Controls(strControlName).SetFocus

Did I get it this time?
 
G

Guest

I'll give it a shot.

Thanks

Kevin D

Storrboy said:
Kevin D. said:
I want to move to the last control to have the focus if the last control was
ItemNum, otherwise to the default control.

Kevin D

"Storrboy" wrote:


I think I'm half asleep today. I've missed or misread a great many things
today.
Before you do your navigation code, store the name of the last control to
have the focus by setting a form public variable to
Screen.PreviousControl.Name. If no other controls have had focus, then an
error will occur, so be sure to allow the code to continue if one occurs.
Example

'In the declaration section of form module
'-------------------------------------------
Dim strContrlName As String

'Before navigation code in button
'-------------------------------------------
On Error Resume Next
strControlName = Screen.PreviousControl.Name
If Err <> 0 Then strControlName = ""


In the OnCurrent event of the form (so that for each change in record
position this will fire) check the variable and move to the desired control.
I don't know what you mean by the "default control" as when using the
built-in nav buttons, the focus stays with the one that had it last - so you
may need to specify which is the "default"

If strControlName <> "ItemNum" Then strControlName = "[DefaultControlName]"
Me.Controls(strControlName).SetFocus

Did I get it this time?
 

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