I have a table .. and I want to return a count of records that meet the criteria. (The criteria will be the number of records for a certain time period .. for example, last 24 hours, week, month and year and total records) This part is ok .. as I just change the criteria, I just want to find out the most efficient way to get that count number.
The only variable here is the RADIO number ... which will be from 0 to 16384. I just need a COUNT of the number of records .. I do not need any records returned, just a count. But the table is large and will grow more in time.
I just want the most efficient way to do so.
So here is a sample record .. and fields from Transmissions Table.
TransDate TransTime Radio Type Group
2014/08/09 12:23:23 AM 5005 TR 546
2014/08/23 11:23:24 AM 5002 TR 547
2014/09/02 07:34:23 PM 5010 TR 561
So .. my "Radio" value is entered in a form .. named txtSearch for display in txtCount for example.
So .. here are the options that I have come up with:
Method 1:
lngCount = DLookup("Count","qryTransPerYear") using select as below.
SQL from qryTransPerYear = SELECT Count(*) AS [Count] FROM Transmissions WHERE Transmissions.Type="TR" AND Year([TransDate])=Year(Date()) AND Transmissions.Radio=[Forms]![frmMainSwitchboard].[subSearchId].[Form].[txtSearch];
Me!txtCount = lngCount
Method 2:
lngCount = ELookup("Count","qryTransPerYear"."Radio = " & iRadio) 'iRadio will contain the radio value from the form.
SELECT Count(*) AS [Count] FROM Transmissions WHERE Transmissions.Type="TR" AND Year([TransDate])=Year(Date());
Me!txtCount = lngCount
Method 3: (don't know if this works .. as I typically use one of the above)
lngCount = "SELECT Count(*) AS [Count] FROM Transmissions WHERE Transmissions.Type="TR" AND Year([TransDate]) = Year(Date()) AND Transmissions.Radio=[Forms]![frmMainSwitchboard].[subSearchId].[Form].[txtSearch];"
Me!txtCount = lngCount
I am not sure all of the methods will work .. I am just throwing this out there. What is the most efficient way to get a count of the records returned ... ?
Method 4 ..
Using DCount ?
I have heard that using the built in functions can be slower .. so, I am not so much looking for a method that works, but just the fastest way to get that count number based on my criteria.
Thanks ..