Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check box to clear value or to re-insert value 3

Status
Not open for further replies.

snoopy80

Technical User
Jun 27, 2001
106
Hi,
Let say I have a form with 5 records that displays:

Last Fist Unit Cost TotCost chkbox
Smith John 2 $5.00 $10.00
Hill Mary 3 $2.00 $6.00
.
.

When I check the chkbox for example on Smith record I need the Cost and TotCost fields to set to Zero, then if I check the chkbox on Hill record, then the cost and totcost is also set to zero. But Now if I uncheck on Hill then cost and totcost would set it back to $2.00 and $6.00 respectively and if I uncheck Smith then $5.00 and $10.00 is restore back.

I have this Afterupdate event on the checkbox:
If Me!chkbox = -1 Then
Me!totcost = 0
Me!cost = 0
ElseIf chkbox <> -1 Then
Me!totcost.Value = varUnits * varcost
Me!cost.Value = varcost
End If

the varUnits and varcost is Global that is used to capture the unit and the cost when the unit textbox is updated in an event
My problem is when I uncheck Smith, it would set the 2 fields to zero then when I uncheck Hill is also set to zero that I want but now if I uncheck Hill, it will restore it back to $2.00 and $6.00 but if I uncheck Smith it also restore back to $2.00 and $6.00 instead of $5.00 and $10.00. I see the problem is the last check store the values in global var that is why it always restore the same value but How can I make it to save and restore the correct value for each record? Appreciate your helps.
 
How are ya snoopy80 . . .

What you need is an extra field in the table for holding the values. This field would be hidden on the form. If this extra field is named [blue]hldCost[/blue] then you'd have:
Code:
[blue]   If Me!chkbox Then
        Me!hldCost = Me!Cost
        Me!totCost = 0
        Me!Cost = 0
    Else
        Me!Cost = hldCost
        Me!totCost = Me!Unit * Me!hldCost
        Me!hldCost = 0
    End If[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks for your reply AceMan1. I tried your solution. It did similar to the problem I had. And if I uncheck more than once the value would be zero out.
I do appreciate your suggestion.
 
Don't reset the hldCost value if Cost is already set to 0 !

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH for your help. I tried this but it did not Zero out on the second uncheck but it still back to my original problem, that is insert back the last value saved.
Using AceMan1 code, when the chkbox is checked, then:
Me!hldCost = me!Cost
this statement will assign the Cost of the current row (the row that is just checked) to hldCost of all rows. as a result if I uncheck another row it will insert the hldCost of a different row. I also tried to set the Control Source property of hldCost to Cost but when the Cost is set 0 so is hldCost.
 
hldCost should be bound to a corresponding field in the underlaying Table/Query.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
snoopy80 . . .

In my post dated [blue]28 Feb 09 20:29[/blue] I did say:
TheAceMan1 said:
[blue]What you need is [purple]an extra field in the table[/purple] for holding the values.[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Yes. You did AceMan1. I misunderstood and did not store in advance the value but instead assigned the Cost to it each time. I modified my codes to store the hldCost in advance and it worked. Thanks for both of your Helps. Appreciate your time.
 
Hey TheAceMan1,

Your post of Feb 28th 09 was immensely helpful! It let me solve a similar problem I was facing; however, one of the fields that copy over don't "show up" until I click in the copied field ... ever heard of that?

Thanks,
-thefourthwall
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top