473,508 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dcount Help

Hey There,

Have a problem, hopefully someone out here can lend me a hand.

Working on an appointment databases, haven't used VBA in ages and I am find
a lot of rust everywhere.

What I'm trying to do, search the databases using Dcount for any records
that match the Date and time of the appointment prior to it being added to
the database, however have not been successful. Moreover I was looking for
an easy way out, that's the reason behind choosing DCount, however if anyone
else can offer a better suggestion I'll be listening. Below is my code,
don't laugh but offer suggestions :) Once I can get beyond the checking to
see if an appointment already exists for that date and time I can move
forward, but I've fallen and cannot get up and need some help!

Private Sub cmdGenerate_Click()

Dim strsTime As Date
Dim strsDate As Date
Dim intX As Integer

strsTime = Me.txtsTime
strsDate = Me.txtsDate

intX = DCount("[AppointmentID]", "tblAppointments", "[sTime] = strsTime AND
[sDate] = #strsDate#")

If intX > 0 Then

MsgBox "Error! An appointment already exists with that time. Choose
another date or time.", vbOKOnly, "McGill University Health Centre:
Appointment Database"

Else
End If

End Sub
Nov 12 '05 #1
4 2993
Ok,

I've figured out the problem, all is working properly now.. with the
exception of the following. I'll repaste the code I'm using, as it's been
modifed..

Private Sub cmdGenerate_Click()
On Error GoTo Err_Generate_Click

'declare some vars
Dim strsTime As Date
Dim strsDate As Date
Dim intX As Integer

'check to see if an appointment exists for the date/time inputed.

intX = DCount("[sDate]", "tblAppointments", "[sDate] = #" & txtsDate & "#
AND [sTime] = #" & txtsTime & "#")

If intX > 0 Then
MsgBox "Error! An appointment already exists with that time. Choose
another date or time.", vbOKOnly, "McGill University Health Centre:
Appointment Database"
GoTo Exit_Generate_Click
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Appointment added successfully!", vbOKOnly
DoCmd.GoToRecord , , acNext
End If

Exit_Generate_Click:
Exit Sub

Err_Generate_Click:
Debug.Print
MsgBox Err.Description
Resume Exit_Generate_Click

End Sub
The problem is, even though after it finds that there is a duplicate record
with that exact date and time, it still add's another one despite the exit
sub command being used after ther error message box was has me completely
lost. Any thoughts would be greatly appericated.

Thanks,

Steve

sturner AT linux dot ca
"Classified" <cl********@linux.ca> wrote in message
news:zI*****************@news01.bloor.is.net.cable .rogers.com...
Hey There,

Have a problem, hopefully someone out here can lend me a hand.

Working on an appointment databases, haven't used VBA in ages and I am find a lot of rust everywhere.

What I'm trying to do, search the databases using Dcount for any records
that match the Date and time of the appointment prior to it being added to
the database, however have not been successful. Moreover I was looking for
an easy way out, that's the reason behind choosing DCount, however if anyone else can offer a better suggestion I'll be listening. Below is my code,
don't laugh but offer suggestions :) Once I can get beyond the checking to see if an appointment already exists for that date and time I can move
forward, but I've fallen and cannot get up and need some help!

Private Sub cmdGenerate_Click()

Dim strsTime As Date
Dim strsDate As Date
Dim intX As Integer

strsTime = Me.txtsTime
strsDate = Me.txtsDate

intX = DCount("[AppointmentID]", "tblAppointments", "[sTime] = strsTime AND [sDate] = #strsDate#")

If intX > 0 Then

MsgBox "Error! An appointment already exists with that time. Choose
another date or time.", vbOKOnly, "McGill University Health Centre:
Appointment Database"

Else
End If

End Sub

Nov 12 '05 #2
If you store the date as a general date, you'll just have both the
date and time in the same field... then it's simple.

Public Function ApptCount(ByVal dtDateStamp As Date)
ApptCount = DCount("[ApptDateTime]", "tblAppts",
"[ApptDateTime]=#" & dtDateStamp & "#")
End Function
Of course, if you have regular appointment intervals, then you could
do something like set the {PersonID, ApptDate} to be unique (set as
primary key), and the table will do the work for you. But then you
CAN NOT override the rule.

HTH,
Pieter
Nov 12 '05 #3
Move all the code into the BeforeInsert event of the form, and if your
count is already at your limit, set Cancel=True. Then no insert
happens.
Nov 12 '05 #4
What you probably wanted in your code is:

intX = DCount("[AppointmentID]", "tblAppointments", _
"[sTime] = " & Format(strsTime, "\#hh:nn:ss\#") & _
" AND [sDate] = " & Format(strsDate, "\#mm/dd/yyyy\#") )

However, I am not of the logic you are using since the above will only find
exact matches. The most obvious problem is that of the overlapping
appointments.

--
HTH
Van T. Dinh
MVP (Access)


"Classified" <cl********@linux.ca> wrote in message
news:zI*****************@news01.bloor.is.net.cable .rogers.com...
Hey There,

Have a problem, hopefully someone out here can lend me a hand.

Working on an appointment databases, haven't used VBA in ages and I am find a lot of rust everywhere.

What I'm trying to do, search the databases using Dcount for any records
that match the Date and time of the appointment prior to it being added to
the database, however have not been successful. Moreover I was looking for
an easy way out, that's the reason behind choosing DCount, however if anyone else can offer a better suggestion I'll be listening. Below is my code,
don't laugh but offer suggestions :) Once I can get beyond the checking to see if an appointment already exists for that date and time I can move
forward, but I've fallen and cannot get up and need some help!

Private Sub cmdGenerate_Click()

Dim strsTime As Date
Dim strsDate As Date
Dim intX As Integer

strsTime = Me.txtsTime
strsDate = Me.txtsDate

intX = DCount("[AppointmentID]", "tblAppointments", "[sTime] = strsTime AND [sDate] = #strsDate#")

If intX > 0 Then

MsgBox "Error! An appointment already exists with that time. Choose
another date or time.", vbOKOnly, "McGill University Health Centre:
Appointment Database"

Else
End If

End Sub

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5549
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
1535
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
4
7529
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
3305
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
1927
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.
15
2943
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
2
1733
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
7927
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...
2
2518
by: dan.cawthorne | last post by:
Need Some Help, In Modifing this Bit of VBA Code, This the code i use and it works but i want it to go one step further in on the open event of my main start up form If DCount("",...
0
7323
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
7379
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...
1
7038
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
7493
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
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
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
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
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
415
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.