Sue,
I might not be able to give an answer to the main question, here is the
answer to why the BeforeUpdate event exists. It exists to allow you to
validate data before it is saved. Below is the excerpt from the Microsoft
Access Help file:
The following example shows how you can use a BeforeUpdate event procedure
to check whether a product name has already been entered in the database.
After the user types a product name in the ProductName box, the value is
compared to the ProductName field in the Products table. If there is a
matching value in the Products table, a message is displayed that informs
the
user that the product has already been entered.
To try the example, add the following event procedure to a form named
Products that contains a text box called ProductName.
Visual Basic for Applications
Private Sub ProductName_BeforeUpdate(Cancel As Integer)
If(Not IsNull(DLookup("[ProductName]", _
"Products", "[ProductName] ='" _
& Me!ProductName & "'"))) Then
MsgBox "Product has already been entered in the database."
Cancel = True
Me!ProductName.Undo
End If
End Sub
Hopefully this helps in the future.
Wade
Sue said:
Hi Dave,
Again, thanks to all for your assistance.
Here's the info you requested:
BusinessName - is a bound control, a combo box, set to SELECT
tblBusinessName.Business_ID, tblBusinessName.BusinessName FROM
tblBusinessName ORDER BY tblBusinessName.BusinessName;
BusinessCity - is a bound control, a combo box, set to SELECT
tblCity.City_ID, tblCity.CityName FROM tblCity ORDER BY tblCity.CityName;
BusinessZip - is a bound control, a combo box, set to SELECT
[tblZip/PostalCode].[Zip/PostalCode_ID],
[tblZip/PostalCode].[Zip/PostalCodeName] FROM [tblZip/PostalCode] ORDER
BY
[tblZip/PostalCode].[Zip/PostalCodeName];
Once again, I appreciate your assistance.
BTW - if the BeforeUpdate event does nothing, why is it there? Should I
delete it?
Klatuu said:
The Before Update event is not affecting your problem. It does
nothing.
Doug's code should work for you. There is something going on you don't
know
about. It would be helpful if you would specify exactly what kind of
objects
each of the items you reference are. Post back with the following
info:
Control Type, Bound control (Y/N), Field Name it is bound to, Data Type
For:
BusinessName
BusinessCity
BusinessZip
--
Dave Hargis, Microsoft Access MVP
:
Hi Doug - thank you for your willingness to help.
I tried your code, still without success.
The "AfterUpdate" box says [Event Procedure], but the "BeforeUpdate"
property also says [Event Procedure], and the code for "Before Update"
reads
as follows:
Private Sub BusinessName_BeforeUpdate(Cancel As Integer)
End Sub
Not sure how that happened. could that be the problem?
message
Try:
Private Sub BusinessName_AfterUpdate()
' If BusinessName = Duke, then fill in "Durham" for BusinessCity and
"27710"
for BusinessZip
Select Case Me!BusinessName
Case "Duke"
Me!BusinessCity = "Durham"
Me!BusinessZip = "27710"
End Select
End Sub
If that still doesn't work, make sure that the code's actually being
called. Either put a breakpoint in it (click in the margin to the
left
of
the code) or put a message box just to be sure. If it's not being
called,
look at the properties for the BusinessName text box and make sure
that
the AfterUpdate event says [Event Procedure].
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
I want the BusinssCity field & BusinessZip field to be automatically
filled in with Durham and 27710 respectively if the BusinessName =
Duke.
What's wrong with this code?
Private Sub BusinessName_AfterUpdate()
' If BusinessName = Duke, then fill in "Durham" for BusinessCity
and
"27710" for BusinessZip
Select Case BusinessName
Case "Duke"
BusinessCity = "Durham"
BusinessZip = "27710"
End Select
End Sub
Thanks!