473,480 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Difference between DCOUNT and SQL Query attached

108 New Member
Ran both with same values in the form and the SQL query retrieves a row and the VBA code doesnt (DCOUNT)

Ran them both at same time ???? very confused

Also later changed field Date to booking_date and still the same results!

Expand|Select|Wrap|Line Numbers
  1. SELECT Booking.* 
  2. FROM Booking 
  3. WHERE (((Booking.Date)=[Forms]![Booking]![DTPicker8]) AND ((Booking.Facility_ID)=[Forms]![Booking]![comboFacility]) AND ((Booking.Area_ID)=[Forms]![Booking]![comboArea])); 

Expand|Select|Wrap|Line Numbers
  1. doublebooking = DCount("reference_number", "booking", "area_ID=" & Forms!Booking!comboArea & " AND Facility_ID=" & Forms!Booking!combofacility & _" AND date=#" & Forms!Booking!DTPicker8 & "#") 
_________________
Thanks for the help & advice, greatly appreciated ~Rob
Dec 1 '06 #1
6 2985
MMcCarthy
14,534 Recognized Expert Moderator MVP
You have to use the correct names including capitalisation.

Try this ...

Expand|Select|Wrap|Line Numbers
  1. doublebooking = DCount("[reference_number]", "Booking", "[Area_ID]=" & [Forms]![Booking]![comboArea] & " AND [Facility_ID]=" & [Forms]![Booking]![comboFacility] & _
  2. " AND [date]=#" & [Forms]![Booking]![DTPicker8] & "#") 
  3.  
Dec 1 '06 #2
robtyketto
108 New Member
Now I get error 2001 You have cancelled the previous operation.

Ive seen this a few times before, no ideas why it appears.
Certaintly havent pressed anything on the keyboard to cause it :(
Dec 1 '06 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Now I get error 2001 You have cancelled the previous operation.

Ive seen this a few times before, no ideas why it appears.
Certaintly havent pressed anything on the keyboard to cause it :(
Without seeing the rest of the code in this procedure I can't help.
Dec 1 '06 #4
robtyketto
108 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub comboArea_Click()
  2. Dim doublebooking As Long
  3.  
  4. MsgBox Forms!Booking!combofacility
  5. MsgBox Forms!Booking!comboArea
  6. MsgBox "*" & Forms!Booking!DTPicker8 & "*"
  7. MsgBox "*" & Forms!Booking!ComboEnd & "*"
  8.  
  9.  
  10. 'doublebooking = DCount("reference_number", "booking", "area_ID=" & Forms!Booking!comboArea & " AND Facility_ID=" & Forms!Booking!combofacility & _
  11. '" AND booking_date=#" & Forms!Booking!DTPicker8 & "#")
  12.  
  13. doublebooking = DCount("[reference_number]", "Booking", "[Area_ID]=" & [Forms]![Booking]![comboArea] & " AND [Facility_ID]=" & [Forms]![Booking]![combofacility] & _
  14. " AND [date]=#" & [Forms]![Booking]![DTPicker8] & "#")
  15.  
  16. MsgBox doublebooking
  17.  
  18.  
  19. If doublebooking > 0 Then
  20.     MsgBox "Double Booked!"
  21. End If
  22.  
  23.  
  24. 'Dim strSQL As String
  25. '  strSQL = "SELECT Area.Area_ID, Booking.Date, Booking.Start_time, Booking.End_time, Booking.Facility_ID " & _
  26. '"FROM Area INNER JOIN (Facility INNER JOIN Booking ON Facility.Facility_ID = Booking.Facility_ID) ON (Facility.Facility_ID = Area.Facility_ID) AND (Area.Area_ID = Booking.Area_ID) " & _
  27. '"WHERE (((Area.Area_ID)=[Me].[comboarea].[Value]) AND ((Booking.Date)=[Me].[dtpicker8].[Value]) AND ((Booking.Start_time)=[Me].[comboStart].[Value]) AND ((Booking.End_time)=[Me].[ComboEnd].[Value]) AND ((Booking.Facility_ID)=[Me].[Combofacility].[Value]));"
  28.  
  29.  
  30. End Sub
Dec 1 '06 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub comboArea_Click()
  2. Dim doublebooking As Long
  3.  
  4. MsgBox Me.combofacility
  5. MsgBox Me.comboArea
  6. MsgBox "*" & Me.DTPicker8 & "*"
  7. MsgBox "*" & Me.ComboEnd & "*"
  8.  
  9.    doublebooking = nz(DCount("[reference_number]", "Booking", "[Area_ID]=" & Me.comboArea & _
  10.    " AND [Facility_ID]=" & Me.combofacility & " AND [date]=#" & Me.DTPicker8 & "#"),0)
  11.  
  12.    MsgBox doublebooking
  13.  
  14.  
  15.    If doublebooking > 0 Then
  16.       MsgBox "Double Booked!"
  17.    End If
  18.  
  19. End Sub
  20.  
Dec 1 '06 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Ran both with same values in the form and the SQL query retrieves a row and the VBA code doesnt (DCOUNT)

Ran them both at same time ???? very confused

Also later changed field Date to booking_date and still the same results!

Expand|Select|Wrap|Line Numbers
  1. SELECT Booking.* 
  2. FROM Booking 
  3. WHERE (((Booking.Date)=[Forms]![Booking]![DTPicker8]) AND ((Booking.Facility_ID)=[Forms]![Booking]![comboFacility]) AND ((Booking.Area_ID)=[Forms]![Booking]![comboArea])); 

Expand|Select|Wrap|Line Numbers
  1. doublebooking = DCount("reference_number", "booking", "area_ID=" & Forms!Booking!comboArea & " AND Facility_ID=" & Forms!Booking!combofacility & _" AND date=#" & Forms!Booking!DTPicker8 & "#") 
_________________
Thanks for the help & advice, greatly appreciated ~Rob
In the first one (SELECT Query) you are passing the full reference to the SQL interpreter.
In the second case (DCount) you are trying to resolve the items in your VBA code - passing literal values to the function instead.
This will work for the date (Forms!Booking!DTPicker8) if, and only if, you have American local settings, as the SQL date format is 'm/d/y' and it ignores local settings. Otherwise (I would recommend always) you need to use Format(Forms!Booking!DTPicker8,'m/d/yyyy').
You also have a 'Line Continuation' character embedded in your code.
...!combofacility & _" AND ...
which may be causing problems.
Just caught another problem, you use '(Booking.Date)=' in the SELECT but just 'date=' in your DCount. This will cause a problem as Date() is a recognised function and it will try to compare it to today's date instead of your field.
Dec 1 '06 #7

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

Similar topics

6
3298
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...
3
3300
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
511
by: solar | last post by:
DCount in a query How can i sum up all the fields in the query? My query consists of the table products.The first field is Productid, the second is ProductName. The next fields are the quantities...
2
12201
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
7926
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...
7
31983
by: Michael R | last post by:
Good afternoon. I'm stucked in composing the syntax for DCount expression in a select query. The query qryCustomers has CustomerID field, the DCount function uses tblLoans with LoanDate and Id fields...
9
5738
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
3
4851
by: ringer | last post by:
I am trying to add a functionality into a db I use for my checkbook that will help me plan for and save money for future large expenses. Into a table called tblFutureTransactions I want to enter...
36
11359
by: bmyers | last post by:
Good afternoon, I am attempting to count only those records within a report, which is based on a query, where Status is equal to Closed. I have tried multiple variations of DCOUNT but am...
0
7033
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
7027
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
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5318
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,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
170
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.