UpdateEvent

J

Joan

Hi,
On an AfterUpdate event for a control on a form I have code that sets
another control on the form to the value that was just updated. The problem
is, that if the user mistakenly enters data in the wrong record's control
with the AfterUpdate event and then upon realizing their mistake tries to
backspace the data out or delete it, then the other control that is affected
by the AfterUpdate event still shows the value originally entered. How can
I get this other control([ReturnedStore]) to also be blank or empty? Below
is my code.

Joan

Private Sub Store_AfterUpdate()
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("EnterStoresQuery", dbOpenDynaset)
If Forms!SalesScreen!Returned = "Y" And Not
IsNull(Forms!SalesScreen![Store]) Then

Forms!SalesScreen!ReturnedStore = Forms!SalesScreen!Store
Forms!SalesScreen!ReturnedSalePrice = Forms!SalesScreen!SalesPrice
End If
rs.Close
db.Close

End Sub
 
E

Emilia Maxim

---------- "Joan said:
Hi,
On an AfterUpdate event for a control on a form I have code that sets
another control on the form to the value that was just updated. The problem
is, that if the user mistakenly enters data in the wrong record's control
with the AfterUpdate event and then upon realizing their mistake tries to
backspace the data out or delete it, then the other control that is affected
by the AfterUpdate event still shows the value originally entered. How can
I get this other control([ReturnedStore]) to also be blank or empty? Below
is my code.

Joan,

see comments inline.
Private Sub Store_AfterUpdate()
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("EnterStoresQuery", dbOpenDynaset)
If Forms!SalesScreen!Returned = "Y" And Not
IsNull(Forms!SalesScreen![Store]) Then

Forms!SalesScreen!ReturnedStore = Forms!SalesScreen!Store
Forms!SalesScreen!ReturnedSalePrice = Forms!SalesScreen!SalesPrice
End If

The code does something only if Store is not empty, there is no action
if user deletes it. Try this instead:

If Forms!SalesScreen!Returned = "Y" Then
If Not IsNull(Forms!SalesScreen![Store]) Then
Forms!SalesScreen!ReturnedStore = Forms!SalesScreen!Store
Forms!SalesScreen!ReturnedSalePrice =
Forms!SalesScreen!SalesPrice
Else
MsgBox "You entered Yes for Returned, but no Store!"
Forms!SalesScreen!ReturnedStore = Null
Forms!SalesScreen!ReturnedSalePrice = Null
End If
Else
'User entered N or left Returned empty
Forms!SalesScreen!ReturnedStore = Null
Forms!SalesScreen!ReturnedSalePrice = Null
End If

If
End Sub

As an alternative, you could do the checking +filling in the form's
BeforeUpdate event.

BTW, why do you load the recordset? It seems like you're doing nothing
with it.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
J

Joan

Thanks Emilia for your reply. I got it to work by setting up 2 new fields
called Store1 and SalesPrice1 which temporarily store the data but pass it
to other fields depending upon the conditions. A returned dog can be resold
so when the salesman enters the store code in Store1, then the store code is
passed to either [Store] or [ReturnedStore] depending upon if this is the
first time the dog is sold, or the second time. The following IfThen
structure worked for me.
If Forms!SalesScreen!Returned = "Y" Then
Forms!SalesScreen!ReturnedStore = Format(Forms!SalesScreen!Store1,
">")

Else
Forms!SalesScreen!Store = Forms!SalesScreen!Store1
End If
If Forms!SalesScreen!Returned = "Y" And Not
IsNull(Forms!SalesScreen![Store1]) Then
Forms!SalesScreen!ReturnedSalePrice = Forms!SalesScreen!SalesPrice1
End If

Thanks again for answering my post.

Joan


Emilia Maxim said:
---------- "Joan said:
Hi,
On an AfterUpdate event for a control on a form I have code that sets
another control on the form to the value that was just updated. The problem
is, that if the user mistakenly enters data in the wrong record's control
with the AfterUpdate event and then upon realizing their mistake tries to
backspace the data out or delete it, then the other control that is affected
by the AfterUpdate event still shows the value originally entered. How can
I get this other control([ReturnedStore]) to also be blank or empty? Below
is my code.

Joan,

see comments inline.
Private Sub Store_AfterUpdate()
Dim db As Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("EnterStoresQuery", dbOpenDynaset)
If Forms!SalesScreen!Returned = "Y" And Not
IsNull(Forms!SalesScreen![Store]) Then

Forms!SalesScreen!ReturnedStore = Forms!SalesScreen!Store
Forms!SalesScreen!ReturnedSalePrice = Forms!SalesScreen!SalesPrice
End If

The code does something only if Store is not empty, there is no action
if user deletes it. Try this instead:

If Forms!SalesScreen!Returned = "Y" Then
If Not IsNull(Forms!SalesScreen![Store]) Then
Forms!SalesScreen!ReturnedStore = Forms!SalesScreen!Store
Forms!SalesScreen!ReturnedSalePrice =
Forms!SalesScreen!SalesPrice
Else
MsgBox "You entered Yes for Returned, but no Store!"
Forms!SalesScreen!ReturnedStore = Null
Forms!SalesScreen!ReturnedSalePrice = Null
End If
Else
'User entered N or left Returned empty
Forms!SalesScreen!ReturnedStore = Null
Forms!SalesScreen!ReturnedSalePrice = Null
End If

If
End Sub

As an alternative, you could do the checking +filling in the form's
BeforeUpdate event.

BTW, why do you load the recordset? It seems like you're doing nothing
with it.

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 

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