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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Before Update vs OnExit



 
 
Thread Tools Display Modes
  #1  
Old November 10th, 2009, 01:39 AM posted to microsoft.public.access.forms
Uschi via AccessMonster.com
external usenet poster
 
Posts: 55
Default 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  
Old November 10th, 2009, 03:05 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default 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  
Old November 10th, 2009, 11:32 PM posted to microsoft.public.access.forms
Uschi via AccessMonster.com
external usenet poster
 
Posts: 55
Default 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  
Old November 11th, 2009, 01:01 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default 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  
Old November 12th, 2009, 10:46 PM posted to microsoft.public.access.forms
Uschi via AccessMonster.com
external usenet poster
 
Posts: 55
Default 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  
Old November 13th, 2009, 12:04 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default 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

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 02:14 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.