I would like to go deeper in D count function:
DCount("*","[qryTable1]","[TicketNo] = " & [TicketNo] & " And ( [TicketTime] < #" & [TicketTime] & "# Or [TicketTime] = #" & [TicketTime] & "# And [User] < '" & [User] & "')")+1
"*","[qryTable1]" - this means that all numbers should be counting in qryTable1.
Would not be better if in this place we can show Access seraching number : 5000020 ?
next there are criteria:
[TicketNo] = " & [TicketNo] - Take current choosen record (last record in our case)
[TicketTime] < #" & [TicketTime] & "# - what does it mean?
or [TicketTime] = #" & [TicketTime] & "# - what does it mean?
And [User] < '" - User should be not empty ?
[User] & "')")+1 - what does it mean?
For the basic information on DCount read this. Let's break this down. Consider the following simple DCount. I've replaced qryTable1 with Table1. It could be either.
Code:
Total Count: DCount("*","[Table1]")
If you observe this in the attached database you will see it gives you the count of all of the records for each record. Not very interesting. Let's add some criteria. Consider
Code:
Count of Same: DCount("*","[Table1]","[TicketNo] = " & [TicketNo])
This will give the count for records with the same ticket number. The & [TicketNo] in the criteria concatenates the TicketNo of the current record in the criteria. So if you are look at a line in the output that has TicketNo 5000015 the DCount for that record turns into:
Code:
Count of Same: DCount("*","[Table1]","[TicketNo] = 5000015)
Now if we want the count of the tickets that are the same and have times earlier we add [TicketTime] < #" & [TicketTime] to the criteria and we have
Code:
Count of Earlier: DCount("*","[Table1]","[TicketNo] = " & [TicketNo] & " And [TicketTime] < #" & [TicketTime] & "#" )
Here the time of each record is concatenated in. If you look at the output you will see that for TicketNo 5000020 at time 6/3/2016 15:45 the count is zero as there are no records with this ticket number that are earlier. In the final expression I added one to this so the counts starts at one.
If the times are always different this expression would be enough. The addition criteria is added for cases where the times are the same. When the times are different this
Code:
[TicketTime] < #" & [TicketTime]
is the controlling part and when they are the same this
Code:
[TicketTime] = #" & [TicketTime] & "# And [User] < '" & [User] & "'
is the control part.
p.s. I have tried do similar Query but with other fields and other Time/Date format and NumKolenosc(SequenceNO) is all the time = 1.
Please find my trials in attachment
The sequence numbers are the same because the time and users are the same or null. If the TicketNo, Time, and User are the same the sequence number will be the same. How could it be different?
Why can't i do:
SELECT TicketNo, TicketTime, User FROM Table1 and i ahve to have SELECT Table1.TicketNo, Table1.TicketTime, Table1.User?
You should be able to do that. The only time you have to specify the table is when two fields in different tables have the same name, e.g., Table1.TicketNo,Table2.TicketNo,