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

help with how to Dcount two fields in one table

govnah
9
Hi everybody,

I am struggling with finding the write way to achieve a certain task. I hope someone can help me.

Problem:
I have a table
[reservation_tb]
-reserveID
-roomID
-from :[date datatype]
-to :[date datatype]
-status

On Reservation form. I have a button that will check if the reservation_tb table has a room reserved within the date of the new reservation.

Solution Attempt:
I tried to use a DCount function but it seams to be giving me the wrong result.

Expand|Select|Wrap|Line Numbers
  1. Dim intRoomID, num As Integer
  2. Dim varFrom, varTo
  3.  
  4. varFrom = Me.from.Value
  5. varTo = Me.to.Value
  6.  
  7. intRoomID = Me.comboRoom.Value
  8.  
  9. num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & " _
  10. And [from] between " & varFrom & " and " & varTo & "")
  11.  
  12. If num > 0 Then
  13.     MsgBox "Already Exist"
  14. Else
  15.     MsgBox "Reserved Succesfully"
  16. End If
  17.  
when i debug, it looks like the value in the [from] is from the FORM and not from [reservation_tb].

I can't quite figure out how to solve that.
Thank You in advance.
Jul 26 '10 #1

✓ answered by MikeTheBike

@govnah
Hi

I havn't the time just now to study your code, but I did think before that you had not considered the 'to' date, so maybe this will help
Expand|Select|Wrap|Line Numbers
  1. num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
  2.           "And [from] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
  3.  
  4.     num = num + DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
  5.           "And [to] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
  6.  
  7.     If num > 0 Then
  8.         MsgBox "Already Exist"
  9.     Else
  10.         MsgBox "Reserved Succesfully"
  11.     End If
??

This could, of course, be done in one DCount(), but that looked more difficult to understand!

MTB

4 1958
MikeTheBike
639 Expert 512MB
Hi

Have you tried this

Expand|Select|Wrap|Line Numbers
  1. num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & " _ 
  2. And [from] between #" & Format(varFrom,"mm/dd/yy") & "# and #" & Format(varTo,"mm/dd/yy") & "#")
??


MTB
Jul 26 '10 #2
govnah
9
Thank you soo much for replying. I tried your suggestion but now its giving me "0" as a result instead of "1".


This is me trying to make my problem more clear.


----------------
reservation_tb (current records)
reserveID | roomID | from | to | status
1 | 2 | 26/07/2010 | 30/07/2010 | Reserved
2 | 4 | 26/07/2010 | 28/07/2010 | Reserved

the above is the current records in the table that i want to insert into


----------------
Reservation Form (new)
reserveID | roomID | from | to | status
3 | 2 | 26/07/2010 | 28/07/2010 | Reserved

this insertion should not be possible because the "[roomID]=2" is already reserved on the same day "[from]=26/07/2010"


----------------
Reservation Form (new)
reserveID | roomID | from | to | status
3 | 2 | 28/07/2010 | 28/07/2010 | Reserved

The above update should also not be able to work because [roomID]=2 is already reserved AND "[from]=28/07/2010" falls within the date which "[roomID]=2" is reserved in the "reservation_tb (current records)"... "[from]=26/07/2010" "[to]=30/07/2010"


----------------
Reservation Form (new)
reserveID | roomID | from | to | status
3 | 2 | 1/08/2010 | 3/08/2010 | Reserved

However, the above insertion should be able to work because "[from]=1/08/2010" "[to]=3/08/2010" is deffirent from what already exist in reservation_tb (current records).
Jul 26 '10 #3
MikeTheBike
639 Expert 512MB
@govnah
Hi

I havn't the time just now to study your code, but I did think before that you had not considered the 'to' date, so maybe this will help
Expand|Select|Wrap|Line Numbers
  1. num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
  2.           "And [from] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
  3.  
  4.     num = num + DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
  5.           "And [to] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
  6.  
  7.     If num > 0 Then
  8.         MsgBox "Already Exist"
  9.     Else
  10.         MsgBox "Reserved Succesfully"
  11.     End If
??

This could, of course, be done in one DCount(), but that looked more difficult to understand!

MTB
Jul 27 '10 #4
govnah
9
@MikeTheBike

Thank you so much for taking time out to help me out :)

YOUR CODE SOLVES THE PROBLEM. Thank you again
Jul 28 '10 #5

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

Similar topics

2
by: David Heller | last post by:
I have this schema I exported from a database running mysql version 4.01 I'm trying to create this table on a server running mysql 3.23 I keep getting a syntax error near line 11 (I added the line...
21
by: BT | last post by:
I inherited a simple page that needs to be Strict HTML and I'm not very familiar with this standard. What I'm trying to do _should be_ pretty simple so I hope someone can point me in the right...
21
by: Dan | last post by:
Hi, just ran into my first instance of a backend Access97 database not compacting. I'm getting the "MSACCESS.EXE has generated errors.." message on compact. I've narrowed it down to the largest...
3
by: Richard Holliingsworth | last post by:
Hello: Thanks for reading this post. I have (had) a relatively small table of about 12 fields that has now bloomed into a monster of 38 fields and could get bigger. It's way past time to...
2
by: Mark | last post by:
Hello, We currently have a table (access 2000) that has the following values: 706 6789 1 5.11 N N 20040923 792 6592 1 10.05 N N 20040923 795 1605 1 6.30 N N 20040923 807 5817 1 6.33 N N...
1
by: moischmoe | last post by:
I am using MS Access 2000. I have a database that I use to keep weekly attendance records. In my table, each record consists of the fields: name, week 1, week 2, week 3, ect...(each week I add a...
1
by: simho3000 | last post by:
Hi, I don't think my mind in good shape on this today, really need your expert on this I got two simple tables without key Table A has 2 fields, Date and volume, e.g. 1/May/05 and the actual...
1
by: Paul | last post by:
Hi, I wish to be able to add tables to a sql server database at runtime from my asp.net application. As well as creating fields I also wish to be able to create indexes on selected fields and to...
4
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that...
5
by: Gordon Youd | last post by:
Randy Harris and Bob Quintal have tried to help me with my data base report problem, for which I thank them. The suggestions they gave me still do not seem to work and I am still getting false...
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: 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
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
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
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.