473,394 Members | 1,737 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,394 software developers and data experts.

DCount() Confusion

I am having the same problem... I am using Access 2003 SP3 and in the table, the records are:
Expand|Select|Wrap|Line Numbers
  1. no    BordIndex    name     signoff        comments
  2. ------------------------------------------------------
  3. 1         71       Prod1       0           -
  4. 2         71       Prod2       1           Bad
  5. 3         71       Prod3       0           -
  6. 4         71       Prod4       1           Expired
  7. 5         71       Prod5       1           Broken
  8. 6         71       Prod6       1           Bad
  9.  
please note that this is a part from a big table that holds another "BordIndex" numbers for other Bords. I used this code to store the numbers of none signed off products which belongs to the Bord number 71:

Expand|Select|Wrap|Line Numbers
  1. N = DCount("SignOff", "Prod", "BordIndex = 71 and SignOff =1")
and insted of returning 4, it just return 6.

Please help me with this.

Thanks.

** Edit ** This was split from a related thread (Why is DCount expression returning wrong values?).
Nov 9 '10 #1
16 2785
NeoPa
32,556 Expert Mod 16PB
Ahmed, I can see that you tried hard to do things correctly, so I will simply say we don't allow new questions in existing threads. I have moved it to it's own thread for you and added links between the two threads in case it helps.
Nov 9 '10 #2
NeoPa
32,556 Expert Mod 16PB
I can't easily see why this wouldn't work. Certainly it's untidy, but probably would work in normal circumstances.
Tidying the code to be explicit :
Expand|Select|Wrap|Line Numbers
  1. N = DCount("*", "Prod", "([BordIndex] = 71) and ([SignOff] = 1)")
I expect that one of the fields is mishandled though. What datatypes are the fields [BordIndex] and [SignOff]? If they're not both numeric then that would explain the problem.
Nov 9 '10 #3
ADezii
8,834 Expert 8TB
DCount() should provide the correct answer in this case:
  1. Are the Data Types of the [BordIndex], and [signoff] Fields NUMERIC?
  2. Try a Variation on DCount() and see what happens:
    Expand|Select|Wrap|Line Numbers
    1. N = DCount("*", "Prod", "BordIndex = 71 and SignOff =1")
Nov 9 '10 #4
ADezii
8,834 Expert 8TB
Sorry NeoPa, always stepping on your toes! Is this because your feet are so big? (LOL).
Nov 9 '10 #5
Hi NeoPa,

Thnaks for your solution, it works, but why it was not working before? I mean if I write the same code, which was cosing the problem in the "Immediate" box in VBA editor, it gives 4 which is currect, rather than 6 which is wrong, but only in the run-time it return 6 rather than 4. Can you explaine to me what the reson?

Sorry for putting this question in an existing thread.

Also, many many thanks to all of you, who tried to help me by writing them suggestions.

Thanks.

Ahmed
Nov 10 '10 #6
Hi ADezii,

I tried it, but it still gives 6. Both are Integers.

Thanks.

Ahmed
Nov 10 '10 #7
Hi All,

It back again... I don't know why!

It back giving me 6 rather than 4.

I think it's a bug in MS Office Access 2003.

Thanks.


Ahmed
Nov 10 '10 #8
NeoPa
32,556 Expert Mod 16PB
Right! This is clearly confusing, and we have some information but could do with some more.

Firstly, as I said before, I can't see why your earlier code wouldn't have worked. It's not tidy - but nor is it wrong as far as I can see. This is particularly true as you've now confirmed that both fields are of type integer.

Next, to move forward with this we need you to paste exactly the code you're using (just the DCount() line should be adequate), then redo the data grab and confirm for us that the results still exactly match the data you shared with us in your OP (By the way - not many posters are clever enough to include the data as you did - Smart move). Try this SQL to see exactly what results you get. If they're exactly the same as the data you already posted just confirm that, but if they're different then please post the new results for us to work with :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [No]
  2.        , [BordIndex]
  3.        , [Name]
  4.        , [SignOff]
  5.        , [Comments]
  6. FROM     [Prod]
  7. WHERE    ([BordIndex] = 71)
  8. ORDER BY [No]
Obviously, leave out references to any fields which aren't actually in the table if there are any.

Lastly, it's important to say under exactly which circumstances the results are returned correctly and under which they are not.

ADezii:
Sorry NeoPa, always stepping on your toes! Is this because your feet are so big? (LOL).
That's not a polite way to talk to a Sasquatch!!
Nov 10 '10 #9
ADezii
8,834 Expert 8TB
It's not a Bug in Access 2003, since that is what I tested it on, and the result returned was 4.
Nov 10 '10 #10
Hi NeoPa,

Thanks for trying helping me, the code is:

Expand|Select|Wrap|Line Numbers
  1. Dim Cn As New Adodb.Connection
  2. Dim Rs As New Adodb.Recordset
  3. Dim SQL As String, LNo as Long, N as Integer
  4.  
  5.  
  6. With Cn
  7.   .Provider = "Microsoft.Jet.OLEDB.4.0"
  8.   .ConnectionString = Application.CurrentProject.FullName 
  9.   .Open
  10. End With
  11.  
  12. SQL = "Select * from Bords"
  13.  
  14. With Rs
  15.   .Open SQL, Cn, adOpenDynamic, adLockOptimistic
  16.   .MoveFirst
  17.   Do While Not .EOF
  18.     LNo = .Fields("BordIndex")
  19.     N = DCount("SignOff", "Prod", "([BordIndex] = " & LNo & ") and ([SignOff] =1)") 
  20.  
  21. ..............
  22.  
  23.  
As you see, the value of N in the design time (if we run the code in "Immediate" window) will be 4, but during the execution of the code (Run time) it's return 6.


Thanks.
Nov 15 '10 #11
NeoPa
32,556 Expert Mod 16PB
Ahmed, much time will be wasted if I need to point your attention back to a previous post. Please reread post #9 and respond to all of it as well as you can. Thank you for the code, but that was only one part of what I said was needed.

As for the code you've posted, I see no problem with it. I would use "*" for the first parameter (as suggested), but there are no scenarios where you would not get the same result when using "SignOff" instead.

You say the Runtime returns 6 and the code, when run in the immediate window, returns 4, but what if the code is run in the MDB (or ACCDB) form but without the IDE (within which is the Immediate Pane) even open?
Nov 15 '10 #12
Hi NeoPa,

Sorry for not reading your previous reply compleatley.

Yes, I can confirm that the SQL query you provide is giving the same result I provide.

Basicly, I am using MS Access 2003, with VBA code, and as I said, the value of N in the design time (if we run the code in "Immediate" window) will be 4, but during the execution of the code (Run time) it's return 6. In other words, if I run a query to get the number of non-signed off products, it return 4 (in Queries tab -> New Query), and if I typed in the Immediate window the DCount line, it also return 4. But only when the VBA code is being executed and the result of the DCount is being stored in the variable N, it will give 6.

I am using Windows XP Pro SP3, with MS Access 2003 SP3 linked on a domain controller network.

I've wrote this code to replace the DCount, and it works, but (As you know) it will take a long time in a large number of records.
Expand|Select|Wrap|Line Numbers
  1. Private Function CalcErrBdx(ByVal BordIndex As Long) As Long
  2.     Dim GTCN As New ADODB.Connection, GTRs As New ADODB.Recordset, GTSQL As String, Rees As Variant
  3.     With GTCN
  4.         .Provider = "Microsoft.Jet.OLEDB.4.0"
  5.         .ConnectionString = Application.CurrentProject.FullName
  6.         .Open
  7.     End With
  8.  
  9.     Rees = 0
  10.     GTSQL = "select * from prod" 
  11.  
  12.     With GTRs
  13.         .Open GTSQL, GTCN, adOpenDynamic, adLockOptimistic
  14.         If .EOF = True And .BOF = True Then
  15.             Rees = 0
  16.         Else
  17.             .MoveFirst
  18.             DoEvents
  19.             Do While Not .EOF
  20.                 If .Fields("BordIndex") = BordIndex Then
  21.                     If .Fields("SignOff") = 1 Then Rees = Rees + 1
  22.                 End If
  23.                 .MoveNext
  24.             Loop
  25.         End If
  26.         .Close
  27.     End With
  28.  
  29.     Set GTRs = Nothing
  30.     GTCN.Close
  31.     Set GTCN = Nothing
  32.     CalcErrBdx = Rees
  33. End Function
  34.  
By the way, there are 2 tables, the first one is PROD and the second one is BORDS, and [BordIndex] is the brimary key for the BORDS table, linked with a foregn key [BordIndex] in PROD table. the construction code for both tables are:
Expand|Select|Wrap|Line Numbers
  1. Create Table Bords
  2. (
  3. BordIndex     Integer  Primary Key,
  4. BordLocation  Varchar(20),
  5. Manager    Varchar(20)
  6. );
  7.  
  8. Create Table Prod
  9. (
  10. No     Integer  Primary Key,
  11. BordIndex  Integer  Referances Bords(BordIndex),
  12. Name    Varchar(20),
  13. SignOff   Integer,
  14. Comments  Varchar(100)
  15. );
  16.  
  17.  
and the data in the tables are:

Expand|Select|Wrap|Line Numbers
  1. Bords Table:
  2. BordIndex    BordLocation     Manager
  3. -------------------------------------- 
  4. 70           North East       Bob
  5. 71           South West       James 
  6. 72           North West       Alan
  7.  
  8.  
  9. Prod Table:
  10. no    BordIndex    name     signoff        comments 
  11. ------------------------------------------------------ 
  12. 1         71       Prod1       0           - 
  13. 2         71       Prod2       1           Bad 
  14. 3         71       Prod3       0           - 
  15. 4         71       Prod4       1           Expired 
  16. 5         71       Prod5       1           Broken 
  17. 6         71       Prod6       1           Bad 
  18.  

Thanks and sorry if I didn't reply with compleatley what you want in reply #9.

Thanks.
Nov 15 '10 #13
Hi ADezii,

Please see:http://support.microsoft.com/kb/945674
Nov 15 '10 #14
NeoPa
32,556 Expert Mod 16PB
Ahmed, I can see that you're doing your best to answer, so I'm happy with that. Unfortunately there are still some things I need from you. I will be as clear as I can :
  1. Runtime. I think maybe you are not using this word with it's normal meaning. Maybe if I explain that you will understand better and be able to answer.

    The Runtime is a version of the Access application itself which doesn't allow viewing or updating of the database design at all (See Understanding the Microsoft Access Runtime Engine).

    I think when you use the word Runtime you are talking about when the project runs at full speed without any debugging interference. Is that right?
  2. One of the main things I wanted to see from post #9 is the results of the query whose SQL I posted. Without this I don't know what I'm working with data-wise.

    ** Edit **
    I've just seen your updated post. Is the data simply a repeat of what you posted earlier, or is it what I requested - an up-to-date run of that SQL (from post #9)? The data doesn't look much like the sort of real-life data you might find in a real table, but maybe that's simply because it's a test table with test data in it.

I'm sure if you can respond to these two points we can move forwards.
Nov 15 '10 #15
Hi All,

Thanks for your effort, I did submit this question in MSDN forum, and I got the answer.
http://social.msdn.microsoft.com/For...5-1c6daacecfbd

Thanks for all of you.

Ahmed Eissa
Nov 22 '10 #16
NeoPa
32,556 Expert Mod 16PB
An interesting work-around Ahmed. Some good advice from what I saw, and clearly it helped you.

It's not an answer to the question you asked though (That's not a problem - I just wanted to make it clear for those coming along afterwards with a similar problem to the question you asked).

Good luck for the rest of your project.
Nov 22 '10 #17

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...
11
by: N J | last post by:
Hi, I was given this code by a member on here but I am still stuck...I want to be able to see if there is other orders in the table based on the email address. But I keep getting #Name? what does...
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: 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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.