Buttons

D

Donbenz

I have a form set up from tracking inventory after it is inspected. I have
two buttons one that says pass one that says fail. After 5 consecutive
shipments pass I want a message box to pop up. I have the code so that after
5 clicks the message box pops up. My question is how can I reset the count
if the fail button is pressed. Here is the code I am using.

Static intX As Integer
intX = intX + 1
If intX = 1 Then
DoCmd.GoToRecord acDataForm, "5 Lot Proof block Log", acNext
DoCmd.SendObject acSendReport, "5 Lot Inspection", "SnapshotFormat(*.snp)",
"", "", "", "Failure of the 5 Lot Proof Block Log", "To Whom it may concern,

The Certified Supplier has failed their
first 5 lot proof block log inspection. This is the second failure of the
part since the inspection began.", True, ""
End If
If intX = 2 Then
mybox = MsgBox("Third Consecutive Failure For The Part?", vbYesNo)
End If
If mybox = vbYes Then
DoCmd.OpenForm "Certified Supplier Performance Tracking Log", acNormal
DoCmd.SendObject acSendReport, "5 Lot Inspection",
"SnapshotFormat(*.snp)", "", "", "", "Third Failure of the 5 Lot Proof Block
Log", "The Certified Supplier has failed their third consecutive 5 Lot Proof
Block inspection. They are to be removed from the certified supplier
program", True, ""
DoCmd.Close acForm, "5 Lot Proof Block Log", acSavePrompt
End If

Any help would be appreciated.

Thanks,

Donbenz
 
K

Klatuu

I am assuming your static variable (intX) is in the Click event of the Pass
button. You can't get to it frm the Fail button click event. What I would
suggest is to put it in it's own function so either sub can find it. Here is
one that will work for you

Static Function PassCount(Optional ByVal varNewVal As Variant) As Integer
Dim varOldVal As Variant

If Not IsMissing(varNewVal) Then
varOldVal = varOldVal + varNewVal
End If
PassCount = varOldVal
End Function

And here is how you can use it.
When you click the Pass button:
PassCount(1)

When you want to test the current value:

If Passcount() >= 5

In the Fail button code when you want to reset it:

PassCount(-Passcount)
 

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