Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Before Update vs OnExit

1 view
Skip to first unread message

Uschi via AccessMonster.com

unread,
Nov 9, 2009, 8:39:09 PM11/9/09
to
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

John W. Vinson

unread,
Nov 9, 2009, 10:05:14 PM11/9/09
to
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]

Uschi via AccessMonster.com

unread,
Nov 10, 2009, 6:32:29 PM11/10/09
to
John,

Many thanks for reply. I get an error message (Error: =) on the first line
of the code.
What am I doing wrong?

Uschi

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

John W. Vinson

unread,
Nov 10, 2009, 8:01:10 PM11/10/09
to
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.

Uschi via AccessMonster.com

unread,
Nov 12, 2009, 5:46:41 PM11/12/09
to
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.

--

John W. Vinson

unread,
Nov 12, 2009, 7:04:45 PM11/12/09
to
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.

0 new messages