keeping focus on a control

  • Thread starter BBC via AccessMonster.com
  • Start date
B

BBC via AccessMonster.com

I have a combobox has had focus set, filled by a query whose initial state is

-nothing is selected- (-1).
I do not want the user to go to any other controls (except maybe my EXIT
button) withought having selected a record from the combobox1. I do put up a
warning message but not sure that is adequate.

1) I have tried setting focus back to its self on the "lost focus" event but
that didn't work.

2) Tried sending it to another (logically the next control) bound combobox2
("got focus") which was to test for nothing selected and send it back to the
other combobox1 but combobox2 couldn't get focus (error).

Even if 1) above had worked not not sure how my EXIT could ever have gotton
focus without having selecting something and then exiting, bad user
interaction.
 
D

Dirk Goldgar

BBC via AccessMonster.com said:
I have a combobox has had focus set, filled by a query whose initial state
is

-nothing is selected- (-1).
I do not want the user to go to any other controls (except maybe my EXIT
button) withought having selected a record from the combobox1. I do put
up a
warning message but not sure that is adequate.

1) I have tried setting focus back to its self on the "lost focus" event
but
that didn't work.

2) Tried sending it to another (logically the next control) bound
combobox2
("got focus") which was to test for nothing selected and send it back to
the
other combobox1 but combobox2 couldn't get focus (error).

Even if 1) above had worked not not sure how my EXIT could ever have
gotton
focus without having selecting something and then exiting, bad user
interaction.


I think I would disable all controls except the combo box and your Exit
button until something has been selected in the combo box. You can use the
form's Current event (if it's a bound form) or its Open event (if it's
unbound) to set all the other controls' Enabled properties to False, and
then use the combo box's AtferUpdate event to set them to True if something
has been selected in the combo box.
 
B

BBC via AccessMonster.com

Thanks, good thought.
I think I have to loop through the controls to do do this OR is there a way
to do it all at once. As well, I think I'll need to test each one for type
to know if they can be disabled ???

Another question related to this same form. Is it possible to stop Access
from automatically saving records when it moves to a another (adds a NEW
record), or at least to trap it and stop it. I do manage my own navigation
controls (and save, undo, etc) but I've had this happen so looking to stop it
or understand what event might capture it. It almost seems like it thinks
it's dirty when I don't (and dirty isn't firing)

thanks

Dirk said:
I have a combobox has had focus set, filled by a query whose initial state
is
[quoted text clipped - 19 lines]
focus without having selecting something and then exiting, bad user
interaction.

I think I would disable all controls except the combo box and your Exit
button until something has been selected in the combo box. You can use the
form's Current event (if it's a bound form) or its Open event (if it's
unbound) to set all the other controls' Enabled properties to False, and
then use the combo box's AtferUpdate event to set them to True if something
has been selected in the combo box.
 
D

Dirk Goldgar

BBC via AccessMonster.com said:
Thanks, good thought.
I think I have to loop through the controls to do do this OR is there a
way
to do it all at once. As well, I think I'll need to test each one for
type
to know if they can be disabled ???

You have to either name each control separately, or else tag them so that
you can use a loop to process them. Here's an example procedure that
enables/disables controls by name:

'----- start of example 1 -----
Function EnableDisableControls(EnabledValue As Boolean)

On Error GoTo Err_Handler

Me.txtTextbox1.Enabled = EnabledValue
Me.cboCombo2.Enabled = EnabledValue
Me.chkCheckbox3.Enabled = EnabledValue
' ... and so on

Exit_Point:
Exit Function

Err_Handler:
' If we get an error because we're trying to disable
' the control that has the focus, move the focus to
' a control that will always be enabled, and try again.
If Err.Number = 2164 Then
Me.cboAlwaysEnabled.SetFocus
Resume
Else
MsgBox Err.Description, vbExclamation, "Error " &Err.Number
Resume Exit_Point
End If

End Function
'----- end of example 1 -----

Here's an example procedure that enables/disables controls by looping
through them and checking their Tag properties:

'----- start of example 2 -----
Function EnableDisableControls(EnabledValue As Boolean)

Dim ctl As Access.Control

For Each ctl In Me.Controls
If ctl.Tag = "DisableMe" Then
ctl.Enabled = EnabledValue
End If
Next ctl

Exit_Point:
Exit Function

Err_Handler:
' If we get an error because we're trying to disable
' the control that has the focus, move the focus to
' a control that will always be enabled, and try again.
If Err.Number = 2164 Then
Me.cboAlwaysEnabled.SetFocus
Resume
Else
MsgBox Err.Description, vbExclamation, "Error " &Err.Number
Resume Exit_Point
End If

End Function
'----- end of example 2 -----

When using the tagging/looping approach, you would have set the controls'
Tag properties at design time.

In either case, you would invoke the function like this:

' Disable the controls that shouldn't be available.
EnableDisableControls(False)

' Enable the controls that we previously disabled.
EnableDisableControls(True)
Another question related to this same form. Is it possible to stop Access
from automatically saving records when it moves to a another (adds a NEW
record), or at least to trap it and stop it. I do manage my own
navigation
controls (and save, undo, etc) but I've had this happen so looking to stop
it
or understand what event might capture it. It almost seems like it thinks
it's dirty when I don't (and dirty isn't firing)

If the form thinks it's Dirty, it is. Probably you are programmatically
dirtying it by setting the value of some bound control in the Current event.
When you dirty the form programmatically, the form's Dirty event doesn't
fire.
 

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