Hi Guys Its Great to be here. I am stuck with a problem in making sequenced serial with condition in MS Access. Let's say i have number of machines working for 2 shifts. Every shift i receive a report of downtime for each machine and the same machine in the same shift could have more than one problem. My goal is to count those problems and make a sequenced serial for it. For Example i made it in Excel with countifs formula and working good - see the picture. 4 Conditions (PoNumber-Shift-MachineNumber-Zdate)
I tried everything I know in Access and got stuck. I tried Count(IIf()) but did not get the desired result and the way to do it is a recordset function and I don’t have the ability to do it. Any Help Appreciated Guys.
Edit #1 : Guys i have tried the following before
SELECT TblDownTime.PONumber, TblDownTime.Zdate, TblDownTime.Shift, TblDownTime.MachineNumber AS MachineNum, Count(TblDownTime.Shift) AS CountOfShift
FROM TblDownTime
GROUP BY TblDownTime.PONumber, TblDownTime.Zdate, TblDownTime.Shift, TblDownTime.MachineNumber
HAVING (((TblDownTime.PONumber)=[Forms]![FrmDownTime]![PONum]) AND ((TblDownTime.Zdate)=[Forms]![FrmDownTime]![Zzdate]) AND ((TblDownTime.Shift)=[Forms]![FrmDownTime]![Shift]) AND ((TblDownTime.MachineNumber)=[Forms]![FrmDownTime]![MachineNumber]));
This is a query which apply my conditions and return the last serial of each downtime reason As variable (Sr) in the form. Then after update in MachineNumber field in the form Me.Serial = Sr+1
. This way works fine with one by one record but when i try to paste 20 records at the time it miscalculates and giving me duplicates sometimes. So it is not the best way to go. I need a way which work fine with pasting multiple records at the time. Thanks again.
Edit #2 i use the generated serial to be formatted like this "Num"&Serial to be like Num1,Num2 to use in the following query
SELECT TblDownTime.PONumber, TblDownTime.Zdate, TblDownTime.Shift, TblDownTime.MachineNumber,
IIf([SerialFormat]="Num1" And [MachineNumber]=[MachineNumber],[ReasonCode],"") AS Code1,
IIf([SerialFormat]="Num1" And [MachineNumber]=[MachineNumber],[Reason],"") AS Reason1,
IIf([SerialFormat]="Num1" And [MachineNumber]=[MachineNumber],[DepartmentResponsible],"") AS Dept1,
IIf([SerialFormat]="Num1" And [MachineNumber]=[MachineNumber],[StoppedFrom],"") AS From1,
IIf([SerialFormat]="Num1" And [MachineNumber]=[MachineNumber],[StoppedTo],"") AS To1,
IIf([SerialFormat]="Num1" And [MachineNumber]=[MachineNumber],[TotalDownTime/Min],"") AS TotalDownTime1
FROM TblDownTime
WHERE (((IIf([SerialFormat]="Num1" And [MachineNumber]=[MachineNumber],[ReasonCode],""))<>""));
i will try the other way in comments tomorrow, And i will be grateful if someone helps me with a recordset function that operates directly on the table and i will but it on OnClose Event in my form .. thanks a lot