Access 2010 keep focus in form asap :)

radek225

Registered User.
Local time
Today, 11:28
Joined
Apr 4, 2013
Messages
307
I have opened several forms. But in active form I want to have some code which not permit leave this form without entering one field e.g. "nameOfOrder". I tried to many ways, but always Access can't keep focus in active form as soon as "nameOfOrder" is refilled. Maybe someone know any way to figure it out? I can't sleep for this problem:p
 
But in active form I want to have some code which not permit leave this form without entering one field e.g. "nameOfOrder". I tried to many ways, but always Access can't keep focus in active form as soon as "nameOfOrder" is refilled.
You don't want the form to lose focus UNTIL the NameOf Order field is typed in. Correct.
Then you say the form loses focus AFTER the field is filled in.
I am not sure what you want.
Dale
 
If I will try to leave form wihout typed in field "nameOfOrder" should appears msgbox " You can't leave this form without typed in 'nameOfOrder'" then I click "ok" and focus goes back to the form which I tried to leave.
It doesn't matter where I try to go. View and focus should be still in form what I tried to leave until I type in field.
 
Last edited:
Try using the form's deactivate event to check whether that control is null. If it is, issue your msg and set the focus back to that control.

-Ron
 
Not working. focus is in the form which i tried to leave, but view is in another form, so I can click "ok" in this msgbox and then I can click something in another form, because view does not return.
 
Not working. focus is in the form which i tried to leave, but view is in another form, so I can click "ok" in this msgbox and then I can click something in another form, because view does not return.
You could set the form to 'Popup' in design view, but that may not give the overall behavior you want. Also, for the textbox.setfocus, be sure to use the formal syntax - ie. not 'me' - since on deactivate technically puts you out of that form's scope (I think; just throwing out novice ideas 'til an expert chimes in.)

-Ron
 
You could set the form to 'Popup' in design view, but that may not give the overall behavior you want.-Ron
Yes exactly
-----------------------------------------------------------------------
I'm not an advanced user so I'm not understand what You try to tell me.
Please see my code.

frmZlecenieMarzena - form what I try to leave, there is a field "Id_K" what should be typed id.
frmGoraZlecenia -subform there is a field "Nazwa" what should be typed in also.

Code:
If (IsNull(Me.ID_K) Or IsNull(Forms!frmZlecenieMarzena!frmGoraZlecenia!Nazwa)) Then
Forms!frmZlecenieMarzena!frmGoraZlecenia!Nazwa.setfocus
    MsgBox "You can't leave this form without typed in 'ID_K' and 'Nazwa'"
    Exit Sub
  End If
 
I'm not advanced either, and I hope someone who is will help. Meantime....

The syntax of your subform reference is wrong. Should be:

Forms!frmZlecenieMarzena!frmGoraZlecenia!Form!Nazwa.setfocus

See here: http://access.mvps.org/access/forms/frm0031.htm

But aside from that, if both those controls must contain values (earlier you only named one you were concerned about), I would test each one separately (separate IF statement for each control). The way you have your code, the focus will be set back to the same control, regardless of which one (or both) is null. I would also put the setfocus code after the msgbox code, just in case the user's dismissal of the msgbox causes an unwanted change in focus.

But beyond all that, I'm not sure it's entirely clear what the issue is. I thought you were saying before that your code does restore the focus to the nulled control, but that the form itself is visually blocked by the form to which the user was trying to transfer.

Also, note that if your overall code were to force the user to visit the critical controls - you could set the focus to one of them when the form opens, for example, and set the focus to the other in the first ones afterupdate event - then you could use both their afterupdate events for the null check.

Play with the above ideas, but if no help, try to post back with greater clarity. Be sure to say which event contains the code. Hopefully a real expert will post. I suspect the issue is a common one, easily solved, but I don't want to confuse it by posting untested code. Good luck.

-Ron
 

Users who are viewing this thread

Back
Top Bottom