Multiple Events

G

Gabby Girl

Please excuse my ignorance but, is it possible to have two different
"BeforeUpdate" events on the same form?

Currently I have a BeforeUpdate on my form re: Allen Browne's Audit Trail
(which by the way works great), but now I need to be able to show the date a
record was added (field name "DateAdded"), modified (field Name
"DateModified") and everything I can find says I should put it in the forms
BeforeUpdate event. Am I on the right track or should I try and grab the
last date from my audit trail table (ie: DLookup last/max date)? Hopefully
this makes sense.

Any advice would be greatly appreciated.
 
A

Arvin Meyer [MVP]

You can have a BeforeUpdate event for each control on a form, as well as the
form itself. You can also have multiple statements in any of the
BeforeUpdate events. If you wanted to, you could also call multiple subs or
functions from a single BeforeUpdate event.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
G

Gabby Girl

Thank you for your quick response Arvin.
I still can't seem to wrap my head around how to put in multiple statements.
Is there a sample of multiple statements somewhere that I could look at ?
Thanks again.
 
K

Klatuu

A statement is a line(s) of code that does one task:

strWholeName = Me.txtLastName & ", " & Me.txtFirstName

An event is a Function. Functions and subs contain statements

Function MakeWholeName(strLast As String, strFirst As String) As String

If IsNull(strLast) Then
MsgBox "Last Name Is Blank"
MakeWholeName = ""
Else
MakeWholeName = strLast & ", " & strFirst
End If
End Function

Functions and subs can be called from a Function or Sub
Function MakeWholeName(strLast As String, strFirst As String) As String

If IsNull(strLast) Then
MakeWholeName = MakeUpAName(strFirst)
Else
MakeWholeName = strLast & ", " & strFirst
End If
End Function

Function MakeUpAName(strFirstName as String) As String
If strFirstName = "John" Then
MakeUpAName = "Doe, John"
Else
MakeUpAName = "Smith" & ", " & strFirstName
End If

End Function

A form can have only one Before Update. Each control on a form (with some
exceptions which have none) can have only one.

Okay, hopefull, that clears up that issue for your.

Now, you say you are using some code from Allen Browne in your Form's Before
Update event. All you need to do is determine where you can add the code you
need to execute so that is does not interfer with the existing code and add
it.
 
G

Gabby Girl

Thank You so much Klatuu. You've cleared that up for me quite nicley. Again
thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top