A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Another Len function not working



 
 
Thread Tools Display Modes
  #1  
Old February 16th, 2010, 04:59 PM posted to microsoft.public.access.queries
Afrosheen via AccessMonster.com
external usenet poster
 
Posts: 70
Default Another Len function not working

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

  #2  
Old February 16th, 2010, 05:55 PM posted to microsoft.public.access.queries
BlairH
external usenet poster
 
Posts: 11
Default Another Len function not working

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

.

  #3  
Old February 16th, 2010, 06:29 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Another Len function not working

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]
  #4  
Old February 16th, 2010, 07:00 PM posted to microsoft.public.access.queries
Afrosheen via AccessMonster.com
external usenet poster
 
Posts: 70
Default Another Len function not working

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/For...eries/201002/1

  #5  
Old February 16th, 2010, 07:27 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Another Len function not working

On Tue, 16 Feb 2010 19:00:55 GMT, "Afrosheen via AccessMonster.com"
u46942@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]
  #6  
Old February 16th, 2010, 09:47 PM posted to microsoft.public.access.queries
Afrosheen via AccessMonster.com
external usenet poster
 
Posts: 70
Default Another Len function not working

Hello John, we meet again.

I probably then should put it in the LostFocus control.

Thanks

John W. Vinson 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!


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201002/1

  #7  
Old February 16th, 2010, 10:50 PM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Another Len function not working

But, you can't cancel the LostFocus or Exit events. You
also can't use Set Focus in the LostFocus event. so you may
have to use the Exit event.

However, users (certainly most that I know) can get
frustrated with that kind of UI. Most recommendations
strongly favor using the FORM's BeforeUpdate event to check
the validity of all fields before saving the record.
--
Marsh
MVP [MS Access]


Afrosheen via AccessMonster.com wrote:
I probably then should put it in the LostFocus control.


John W. Vinson 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!

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:35 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.