Code for reversing procedure

G

Guest

I have an event procedure that when you click a check box it puts a date in
another box like so

Private Sub CallClosed_Click()

If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"
Me!DATECLOSED = Date

With [Forms]![OrdersToshiba]![OrderDetails].[Form].RecordsetClone
.MoveFirst
Do While .EOF = False
.Edit
If ![GoodsReceived] = False Then ![GoodsReceived] = True Else
![GoodsReceived] = True
If ![GoodsReceivedDate] <> Date Then ![GoodsReceivedDate] =
![GoodsReceivedDate] Else ![GoodsReceivedDate] = Date
.Update
.MoveNext
Loop
End With

End Sub

however I want this proccess to apply if the value of the checkbox changes
from False to True and the opposite for True to False .
How would i reverse this process?

I have tried On true and On false commands however is not really working.

Thanks

Andi
 
M

Mike Painter

Andi said:
I have an event procedure that when you click a check box it puts a
date in another box like so

Private Sub CallClosed_Click()

If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"
Me!DATECLOSED = Date

A select Case statement would serve better here and the "ELSE" part can
catch errors.
What happenes if Me!Call Status = "Next Tuesday"?
With [Forms]![OrdersToshiba]![OrderDetails].[Form].RecordsetClone
.MoveFirst
Do While .EOF = False
.Edit
If ![GoodsReceived] = False Then ![GoodsReceived] = True
Else ![GoodsReceived] = True
If ![GoodsReceivedDate] <> Date Then ![GoodsReceivedDate] =
![GoodsReceivedDate] Else ![GoodsReceivedDate] = Date
.Update
.MoveNext
Loop
End With

End Sub
A query would be much faster here. Maybe not noticable with a few records
but worth doing.

however I want this proccess to apply if the value of the checkbox
changes from False to True and the opposite for True to False .
How would i reverse this process?

If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"

Reversing the first two is simply a matter of placing the opposite of them
in the Else part of an If statement
IF CHECKBOX then
If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"
ELSE
If Me!CallStatus = "RF2" Then Me!CallStatus = "RF1"
If Me!CallStatus = "RF5" Then Me!CallStatus = "RF4"
End If

You can only change the "M" value back to one value unless there is
something else that distinguishes "C" from "Other"
 
G

Guest

hi Mike,

Thanks for your valuable response. In answer to your question I shall try
with an update query.
In answer to your questions

1) What happenes if Me!Call Status = "Next Tuesday"? - This will never be,
the status is imported in from another database and refers to fixed criteria.
Although you can type in any stutus you want after. however I have a combo
box with the selection as avalue list. The status is designed to identify and
filter service calls by their status so this is fixed. Either RF1 (open) or
RF2 (closed), RF4 (Not urgent open), RF5 (Not urgent closed)

2) You can only change the "M" value back to one value unless there is
something else that distinguishes "C" from "Other" - I am not worried about
these status remaining like this. The ones we are interested in catching are
RF1, RF2 etc.

3) I am not sure what "A select Case statement" is when you mentioned - "A
select Case statement would serve better here and the "ELSE" part can catch
errors."

Thanks once again - Andi


Mike Painter said:
Andi said:
I have an event procedure that when you click a check box it puts a
date in another box like so

Private Sub CallClosed_Click()

If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"
Me!DATECLOSED = Date

A select Case statement would serve better here and the "ELSE" part can
catch errors.
What happenes if Me!Call Status = "Next Tuesday"?
With [Forms]![OrdersToshiba]![OrderDetails].[Form].RecordsetClone
.MoveFirst
Do While .EOF = False
.Edit
If ![GoodsReceived] = False Then ![GoodsReceived] = True
Else ![GoodsReceived] = True
If ![GoodsReceivedDate] <> Date Then ![GoodsReceivedDate] =
![GoodsReceivedDate] Else ![GoodsReceivedDate] = Date
.Update
.MoveNext
Loop
End With

End Sub
A query would be much faster here. Maybe not noticable with a few records
but worth doing.

however I want this proccess to apply if the value of the checkbox
changes from False to True and the opposite for True to False .
How would i reverse this process?

If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"

Reversing the first two is simply a matter of placing the opposite of them
in the Else part of an If statement
IF CHECKBOX then
If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"
ELSE
If Me!CallStatus = "RF2" Then Me!CallStatus = "RF1"
If Me!CallStatus = "RF5" Then Me!CallStatus = "RF4"
End If

You can only change the "M" value back to one value unless there is
something else that distinguishes "C" from "Other"
 
G

Guest

Hi Mike,

In reference to doing an update Query, the VB is better, because I have
included a variant on the Else Statement for reversing it. - I now have this.
The dates are either removed or added against the subform lines if it is
todays date. So if you accidently close the call, it can now be reversed
without touching any information appended previously etc...

Thanks again for your help.

Andi

Private Sub CallClosed_Click()

If CallClosed Then

If Me!CallStatus = "RF1" Then Me!CallStatus = "RF2"
If Me!CallStatus = "RF4" Then Me!CallStatus = "RF5"
If Me!CallStatus = "C" Then Me!CallStatus = "M"
If Me!CallStatus = "Other" Then Me!CallStatus = "M"
Me!DATECLOSED = Date

With [Forms]![OrdersNonTosh]![OrderDetails].[Form].RecordsetClone
.MoveFirst
Do While .EOF = False
.Edit
If ![GoodsReceived] = False Then ![GoodsReceived] = True Else
![GoodsReceived] = True
If ![GoodsReceivedDate] <> Date Then ![GoodsReceivedDate] =
![GoodsReceivedDate] Else ![GoodsReceivedDate] = Date
.Update
.MoveNext
Loop
End With

Else
If Me!CallStatus = "RF2" Then Me!CallStatus = "RF1"
If Me!CallStatus = "RF5" Then Me!CallStatus = "RF4"
Me!DATECLOSED = Null

With [Forms]![OrdersNonTosh]![OrderDetails].[Form].RecordsetClone
.MoveFirst
Do While .EOF = False
.Edit
![GoodsReceived] = False
If ![GoodsReceivedDate] = Date Then ![GoodsReceivedDate] = Null
Else ![GoodsReceivedDate] = ![GoodsReceivedDate]
.Update
.MoveNext
Loop
End With

End If

End Sub
 
M

Mike Painter

Andi said:
Hi Mike,

In reference to doing an update Query, the VB is better, because I
have included a variant on the Else Statement for reversing it. - I
now have this. The dates are either removed or added against the
subform lines if it is todays date. So if you accidently close the
call, it can now be reversed without touching any information
appended previously etc...

Thanks again for your help.
As long as you are dealing with only a few records or don't mind waiting
there is nothing wrong with writing a *lot* of code that can be handled with
a simple query or two and be much easier to maintain.

More than 20 years ago I stopped assuming that there were any "can't happen"
situations. What if the information from the other system changes, there is
an error in the data or somebody changes it on the form. The Else part of
the CASE statement (found in vb help) can warn of such errors.
 

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