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. -
Dim intRoomID, num As Integer
-
Dim varFrom, varTo
-
-
varFrom = Me.from.Value
-
varTo = Me.to.Value
-
-
intRoomID = Me.comboRoom.Value
-
-
num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & " _
-
And [from] between " & varFrom & " and " & varTo & "")
-
-
If num > 0 Then
-
MsgBox "Already Exist"
-
Else
-
MsgBox "Reserved Succesfully"
-
End If
-
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.
@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 - num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
-
"And [from] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
-
-
num = num + DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
-
"And [to] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
-
-
If num > 0 Then
-
MsgBox "Already Exist"
-
Else
-
MsgBox "Reserved Succesfully"
-
End If
??
This could, of course, be done in one DCount(), but that looked more difficult to understand!
MTB
4 1958
Hi
Have you tried this - num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & " _
-
And [from] between #" & Format(varFrom,"mm/dd/yy") & "# and #" & Format(varTo,"mm/dd/yy") & "#")
??
MTB
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).
@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 - num = DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
-
"And [from] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
-
-
num = num + DCount("[roomID]", "[reservation_tb]", "[roomID] = " & intRoomID & _
-
"And [to] between #" & Format(varFrom, "mm/dd/yy") & "# and #" & Format(varTo, "mm/dd/yy") & "#")
-
-
If num > 0 Then
-
MsgBox "Already Exist"
-
Else
-
MsgBox "Reserved Succesfully"
-
End If
??
This could, of course, be done in one DCount(), but that looked more difficult to understand!
MTB
@MikeTheBike
Thank you so much for taking time out to help me out :)
YOUR CODE SOLVES THE PROBLEM. Thank you again
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |