From: Afrosheen via AccessMonster.com on
Thanks for your time

I have this code:

Private Sub txtUser1_AfterUpdate()
On Error GoTo txtUser1_AfterUpdate_Error

If Len(Nz(Me!txtUser1, "")) = 0 Then
MsgBox "does it work"
Me.txtUser1.SetFocus
End If

On Error GoTo 0
Exit Sub

txtUser1_AfterUpdate_Error:
Err.Description = Err.Description & " In Procedure " &
"txtUser1_AfterUpdate of VBA Document Form_LoginTest"
Call LogError(Err.Number, Err.Description, "txtUser1_AfterUpdate")

End Sub

It will work if there is a space entered in the text box. If I just press
enter it will go to the next field. Even when I put in a break, if I press
enter it just goes to the next field and the afterupdate will not fire.


Thanks for your help.

--
Message posted via http://www.accessmonster.com

From: BlairH on
Can you try your code under OnExit instead of AfterUpdate? An update doesn't
occur if nothing was changed.

Blair

"Afrosheen via AccessMonster.com" wrote:

> Thanks for your time
>
> I have this code:
>
> Private Sub txtUser1_AfterUpdate()
> On Error GoTo txtUser1_AfterUpdate_Error
>
> If Len(Nz(Me!txtUser1, "")) = 0 Then
> MsgBox "does it work"
> Me.txtUser1.SetFocus
> End If
>
> On Error GoTo 0
> Exit Sub
>
> txtUser1_AfterUpdate_Error:
> Err.Description = Err.Description & " In Procedure " &
> "txtUser1_AfterUpdate of VBA Document Form_LoginTest"
> Call LogError(Err.Number, Err.Description, "txtUser1_AfterUpdate")
>
> End Sub
>
> It will work if there is a space entered in the text box. If I just press
> enter it will go to the next field. Even when I put in a break, if I press
> enter it just goes to the next field and the afterupdate will not fire.
>
>
> Thanks for your help.
>
> --
> Message posted via http://www.accessmonster.com
>
> .
>
From: Marshall Barton on
Afrosheen via AccessMonster.com wrote:
>I have this code:
>
>Private Sub txtUser1_AfterUpdate()
> On Error GoTo txtUser1_AfterUpdate_Error
>
>If Len(Nz(Me!txtUser1, "")) = 0 Then
>MsgBox "does it work"
>Me.txtUser1.SetFocus
>End If
>
> On Error GoTo 0
> Exit Sub
>
>txtUser1_AfterUpdate_Error:
> Err.Description = Err.Description & " In Procedure " &
>"txtUser1_AfterUpdate of VBA Document Form_LoginTest"
> Call LogError(Err.Number, Err.Description, "txtUser1_AfterUpdate")
>
>End Sub
>
>It will work if there is a space entered in the text box. If I just press
>enter it will go to the next field. Even when I put in a break, if I press
>enter it just goes to the next field and the afterupdate will not fire.

You can't use SetFocus that way. Instead, try using the
BeforeUpdate event:
Cancel = (Len(Nz(Me!txtUser1, "")) = 0)

Or, if the msgbox is required:
If Len(Nz(Me!txtUser1, "")) = 0 Then
MsgBox "does it work"
Cancel = True
End If

--
Marsh
MVP [MS Access]
From: Afrosheen via AccessMonster.com on
Thanks for getting back so fast. The statement will work is I press the space
bar then enter. If I just press enter the beforeupdate will not fire. It just
goes to the next field


Marshall Barton wrote:
>>I have this code:
>>
>[quoted text clipped - 19 lines]
>>enter it will go to the next field. Even when I put in a break, if I press
>>enter it just goes to the next field and the afterupdate will not fire.
>
>You can't use SetFocus that way. Instead, try using the
>BeforeUpdate event:
> Cancel = (Len(Nz(Me!txtUser1, "")) = 0)
>
>Or, if the msgbox is required:
> If Len(Nz(Me!txtUser1, "")) = 0 Then
> MsgBox "does it work"
> Cancel = True
> End If
>

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/201002/1

From: John W. Vinson on
On Tue, 16 Feb 2010 19:00:55 GMT, "Afrosheen via AccessMonster.com"
<u46942(a)uwe> wrote:

>Thanks for getting back so fast. The statement will work is I press the space
>bar then enter. If I just press enter the beforeupdate will not fire. It just
>goes to the next field

That's correct. BeforeUpdate fires only when there is an update - i.e. when
something (anything other than just a <tab> or <enter>) has been typed into
the control.

If you want the code to run even if the user sets focus to the control and
leaves it without doing anything at all, you'll need to use the LostFocus
event; if you want it to run even if the user just LOOKS at the control and
does nothing with it, I don't think you can!

--

John W. Vinson [MVP]