got/lost focus help please

CaptainBalrog

Registered User.
Local time
Today, 23:45
Joined
Nov 22, 2005
Messages
14
Hi there.

I have a form and on open it traps the user into a combo box where an option must be selected before they can move to another field. I did this by using the lost focus event of the combo to check if an option has been selected and then return the cursor to the combo if no selection has been made.

The problem is that there is an exit button on the form which the user must be able to use to exit the form without interacting with it, say if they opened the form by mistake and just wanted to exit immediately.

I cant find a way to trap users into selecting an option from the combo before filling the rest of the form while still allowing the exit button to work. At the minute you still have to select an option in the combo even if you just want to exit the form.

I have been a notes developer for years so I’m still not that familiar with access and the way its events work so this could easily be a gormless question. Feel free to point that out. Any comments would be much appreciated.
 
what I do is put something like the following into the On Enter event of any other controls on the form (you neednt add anything to your command (exit) button). I am not sure if this is the most efficient way but it works!

Code:
Private Sub Text2_Enter()
If IsNull(Me.Combobox) or Me.Combobox = "" Then
    Beep
    MsgBox "you must select the combobox first"
    Me.Combobox.SetFocus
End If
End Sub
 
gormless. nice. :D

you have to use a different event than lost focus because the very moment you click the exit button your combo has lost the focus, triggering the event.

another approach would be to set - on the form's 'open' event - all of the controls on the form (except the exit button) to disabled (enabled = no). then, in the after update event of the combo, enable all of the disabled controls. (no other code required on the combo).

the nice thing about this approach is that the user can see all of the other controls, so they know there is more to do, but they can only do two things: make a selection or close; they won't waste calories clicking on forbidden controls or on message boxes. :)

there might be a better way than this too...
 
Last edited:

Users who are viewing this thread

Back
Top Bottom