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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|