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
|
|||
|
|||
Before Update vs OnExit
I have a form where all of the fields must be completed before 1. going back
to the Find dialog box (to find a new record to update) or 2. closing the form. In reviewing the threads for the code to use on the fields I am confused as to when one uses Before Update as opposed to OnExit for a field. I should also tell you that the person entering the data likes to "click around". Any thoughts on this? I will also need help with the code. Thanks so much, Uschi -- Message posted via http://www.accessmonster.com |
#2
|
|||
|
|||
Before Update vs OnExit
On Tue, 10 Nov 2009 01:39:09 GMT, "Uschi via AccessMonster.com" u25116@uwe
wrote: I have a form where all of the fields must be completed before 1. going back to the Find dialog box (to find a new record to update) or 2. closing the form. In reviewing the threads for the code to use on the fields I am confused as to when one uses Before Update as opposed to OnExit for a field. The Form's BeforeUpdate event, hands down. It fires when the user has *changed* something in the record, and it can be cancelled if the record is invalid (after a message to the user and an opportunity to fix the problem, preferably!) A textbox or other control has an Exit event, but you can't force the user to even *enter* the control, so it's quite possible that the Exit event will not fire at all. I should also tell you that the person entering the data likes to "click around". Any thoughts on this? I will also need help with the code. Something like Private Sub Form_BeforeUpdate(Cancel as Integer) If Me!txtThis & "" = "" Then MsgBox "Please fill in This!", vbOKOnly Cancel = True Me!txtThis.SetFocus Exit Sub End If similar code for other controls End Sub You can and should certainly get more sophisticated (looping through the form's Controls collection frex) but this is a start. -- John W. Vinson [MVP] |
#3
|
|||
|
|||
Before Update vs OnExit
John,
Many thanks for reply. I get an error message (Error: =) on the first line of the code. What am I doing wrong? Uschi John W. Vinson wrote: I have a form where all of the fields must be completed before 1. going back to the Find dialog box (to find a new record to update) or 2. closing the form. In reviewing the threads for the code to use on the fields I am confused as to when one uses Before Update as opposed to OnExit for a field. The Form's BeforeUpdate event, hands down. It fires when the user has *changed* something in the record, and it can be cancelled if the record is invalid (after a message to the user and an opportunity to fix the problem, preferably!) A textbox or other control has an Exit event, but you can't force the user to even *enter* the control, so it's quite possible that the Exit event will not fire at all. I should also tell you that the person entering the data likes to "click around". Any thoughts on this? I will also need help with the code. Something like Private Sub Form_BeforeUpdate(Cancel as Integer) If Me!txtThis & "" = "" Then MsgBox "Please fill in This!", vbOKOnly Cancel = True Me!txtThis.SetFocus Exit Sub End If similar code for other controls End Sub You can and should certainly get more sophisticated (looping through the form's Controls collection frex) but this is a start. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200911/1 |
#4
|
|||
|
|||
Before Update vs OnExit
On Tue, 10 Nov 2009 23:32:29 GMT, "Uschi via AccessMonster.com" u25116@uwe
wrote: John, Many thanks for reply. I get an error message (Error: =) on the first line of the code. What am I doing wrong? Please post your code, so I or another volunteer can see it. Indicate the fieldnames and control names on the form as well. -- John W. Vinson [MVP] |
#5
|
|||
|
|||
Before Update vs OnExit
Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!txtThis & ""DateIssued"" Then MsgBox "Please enter the Date Issued.",vbOKOnly Cancel = True Me!txtThis.SetFocus Exit Sub End If John W. Vinson wrote: John, Many thanks for reply. I get an error message (Error: =) on the first line of the code. What am I doing wrong? Please post your code, so I or another volunteer can see it. Indicate the fieldnames and control names on the form as well. -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200911/1 |
#6
|
|||
|
|||
Before Update vs OnExit
On Thu, 12 Nov 2009 22:46:41 GMT, "Uschi via AccessMonster.com" u25116@uwe
wrote: Private Sub Form_BeforeUpdate(Cancel as Integer) If Me!txtThis & ""DateIssued"" Then MsgBox "Please enter the Date Issued.",vbOKOnly Cancel = True Me!txtThis.SetFocus Exit Sub End If John W. Vinson wrote: John, Many thanks for reply. I get an error message (Error: =) on the first line of the code. What am I doing wrong? Please post your code, so I or another volunteer can see it. Indicate the fieldnames and control names on the form as well. Well, that is NOT what I suggested. Try: Private Sub Form_BeforeUpdate(Cancel as Integer) If Me!DateIssued & "" = "" Then ' concatenate the control to an empty string ' and compare the result with an empty string MsgBox "Please enter the Date Issued.",vbOKOnly Cancel = True Me!DateIssued.SetFocus Exit Sub End If Since I did not know the name of the control you had in mind, I used an example (txtThis) assuming you would change it. I should have explicitly suggested that you do so. -- John W. Vinson [MVP] |
Thread Tools | |
Display Modes | |
|
|