473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Breaking away from mutiple DCount

374 256MB
Hey all,

Right I have just split my database and uploaded in to my network. Everything is running quicker than I expected however on my admin form I have multiple DCounts.


There are 5 statuses a record can be in:

Initial notification
Awaiting acceptance
Action being taken
Awaiting closure
Closed

I use the DCount function to look up how many records are within each status. For example:

Expand|Select|Wrap|Line Numbers
  1. =DCount("*","qryAdminRecordOverview","NCStatus='Initial Notification'")
This produces the number fine except it takes some time to actually load when I open up my form.

So I basically have two questions here.

Firstly, when I am saying it takes a while to load I am talking around sub 10 seconds for the values to load. I know this is not long but I currently only have around 30 records for the DCounts to look through and I am unsure whether this performance will drastically decrease? I am expecting to have 1000's of records over the course of a year but if it is simply that Dcount just produces a general overhead then I can live with the speed it is at the moment.

Secondly, How can I break away from using DCount. I am thinking a Select Count(*) type of statement in a query, but I am unsure whether this would be any quicker in the long run as I assume I will then have to assing it to my textboxes via VBA. I will then requery whenever I make any changes (I have a view button beside the text boxes to then load the x amount of records of that status below which I can then change the status therefore refresh to update the new counts.) I also have the options of whether I do one big query with each of the 5 status counts in or seperate down in to 5 individuals.

Any input is welcomed.

Thanks,

Chris
Aug 5 '10 #1
7 4731
ADezii
8,834 Expert 8TB
First and foremost, try Indexing the [NCStatus] Field (Duplicates Allowed).
Aug 5 '10 #2
munkee
374 256MB
I had the [NCStatus] indexed already on my main table. I added one to the actual table tblNCStatus and no markable improvement.

I have given the following a try just on a button click event and it returns very fast:

Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim rs As DAO.Recordset
  3. Dim intResult As Integer
  4. Dim strSQL As String
  5.  
  6. Set db = CurrentDb
  7.  
  8. strSQL = "SELECT Count(*) AS [Initial Notification] FROM tbllog WHERE tbllog.NCStatus=1"
  9. Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
  10.  
  11. intResult = rs("Initial Notification")
  12. Me.Text72 = intResult
  13. rs.Close
  14. db.Close
However, after your indexing comment I am kind of worrying this is not just down to my poor database design. I have given normalisation a read in my huge access book and it is hard going to understand sometimes, although I think my tables are set out a lot better than most would have. I am unsure as to where to index most the time so I have just gone with what the database performance analyser has suggested.
Aug 5 '10 #3
ADezii
8,834 Expert 8TB
If the above code works well for you, then you can simply:
  1. Create a Public Function.
  2. Pass it the appropriate NCStatus Code ( 1 to 5).
  3. Set the Control Sources of the Text Boxes equal to the Function, given the appropriate Arguments.
    Expand|Select|Wrap|Line Numbers
    1. Public Function fReturnNotificationCount(bytStatus As Byte) As Integer
    2. Dim db As DAO.Database
    3. Dim rs As DAO.Recordset
    4. Dim strSQL As String
    5.  
    6. Set db = CurrentDb
    7.  
    8. strSQL = "SELECT Count(*) AS [Initial Notification] FROM tbllog WHERE tbllog.NCStatus=" & bytStatus
    9. Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
    10.  
    11. fReturnNotificationCount = rs("Initial Notification")
    12.  
    13. rs.Close
    14. db.Close
    15. Set rs = Nothing
    16. End Function
  4. Control Sources for the 5 Text Boxes:
    Expand|Select|Wrap|Line Numbers
    1. =fReturnNotificationCount(1)
    2. =fReturnNotificationCount(2)
    3. =fReturnNotificationCount(3)
    4. =fReturnNotificationCount(4)
    5. =fReturnNotificationCount(5)
Aug 5 '10 #4
Steven Kogan
107 Expert 100+
Is there a noticeable speed difference if the click event vba uses a simple dcount function? I'd expect a dcount function to run just as fast or faster.

The code called from the button click runs the select statement only once, regardless of how many records are in your form's recordset (so it is fast), while if you have the dcount function in a text box control source it will run once per record (so it is slower).

If you are always displaying just one record then the code can go in the form's current event. Alternately, if you are displaying the dcount information in the header or footer section instead of the detail section then the vba code on the current event could be used and would be faster (since it is run for only the current record).
Aug 5 '10 #5
munkee
374 256MB
To explain further to my setup.

I have an unbound form as an admin overview because I want to be able to oversee how many records are within each status and monitor as they move through my process.


As I stated before I use the dcount in a number of text boxes to count how many records are in each status. Beside these I have a View button. This button loads a continuous sub form below the textboxes with the records of that status.

The selection/loading of the records in to the subform is very fast, it is purely the dcount function which is slow.I assume this is because as has been said the dcount function is firing for each of the records.I think I may switch to the function that has been provided and use that to call the number of records within the select query.

However as I stated before, this is now more worrying me that my database design is bad over the top of everything else as I have read a Dcount should not run THAT slow and when it does it is usually down to poor design. With that being said, this Dcount has only slowed down since splitting and putting my database across the network. During normal usage as a complete file and sitting on my hard drive the dcount runs instant.
Aug 5 '10 #6
Steven Kogan
107 Expert 100+
If the unbound form contains the dcount function then it would be running just once.

Let me know if using the vba function goes noticeably faster than the dcount function. That would be interesting.
Aug 5 '10 #7
munkee
374 256MB
After putting the function in on the same page in seperate boxes to the dcount they both run exactly the same speed. When I remove all of the dcount boxes the function seems to run quicker.

I can requery these boxes and they load pretty fast also. An improvement over the dcount function.
Aug 6 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: jdph40 | last post by:
I posted this problem previously and received excellent help from Wayne Morgan. However, I still have an unanswered question. My form (frmVacationWeeks) is opened from the OnClick event of a...
1
by: Megan | last post by:
Hi Everybody- I've been reading some of the posts about DCOUNT, and I haven't yet found an answer; so, I'm posting this question. I have a report that I'm trying to use DCOUNT on to compute...
4
by: Will | last post by:
Hi, I had a DCount within a module on records in a table where CustSuffix = 0. I now need to DCount where CustSuffix = 0 and the type of cost Suffix (Suffix in table) = G. I can't get both...
6
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a...
2
by: Paul T. RONG | last post by:
Hi, I have a problem with DCount, the following code doesn't work: DCount("", "qryOrder", "( = Me! AND = 'drink')" > 0 Please help. Thank you.
3
by: BerkshireGuy | last post by:
I am having difficulty with using the Dcount function. I am trying to return the number of records from qryIndividualFeedbackDetail where the TimelyManner field is set to 4. So, in the new...
2
by: Kaspa | last post by:
Hello I am trying to create dcount field but is not working I have tried every way possible and I can't get it to work. here is my code: =Dcount("","qryTotalscratched"," in (6,7,8,9) and ...
2
by: ChasW | last post by:
Greetings, I have a form that uses a query as its record source. In the form I have a text box that uses this as its control source: =DCount("", "qry_Search_by_Name") The DCount function...
2
by: Wingz | last post by:
Hiya, Fairly new to Access and was wondering what the best way to perform Dcounts on groups in an Access report. For example, I have 10 employees and the different instances of jobs they can...
8
by: Susan Bricker | last post by:
I have used DCount() to determine the number of records in a recordset. Silly me ... I just noticed that DCount returns an INTEGER, which can hold a maximum value of 32,767. What if the recordset...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.