473,666 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple Criteria in DCount Function

12 New Member
Hi there,

I recently started as a reporting analyst for a large firm. I was asked to work on a project where I import data from Outlook into Access and get a count of emails sent to and from each individual employee. I created a combo box with the control source set as:

=DCount("[To]","Inbox","[To]= 'Firm ABC'" & "Datepart(' d',[Received])=Datepart('d', Today())")

[To] and [Received] are columns in a table named "Inbox". [Received] is in a date format. Essentially what I am trying to do in this function is to count the number of emails from 'Firm ABC' on the current date when you open the report. I have tried almost everything (ex. "& [Received]=Today()"). Any suggestions or help would be greatly appreciated!

Thanks
Jan 22 '18 #1
10 3587
PhilOfWalton
1,430 Recognized Expert Top Contributor
Try changing "Today" (AFIK This is not a word recognised by Access) to Date()

Why is this a Combo Box? I think it should be a Text Box

A further problem is that it is "hard wired" in that you can only let information from Company "Firm ABC", not from Firm XYZ

I suspect you should be looking at 2 input boxes (in the case of the firm, it might be Combo box), 1 to select the date and the other to select the firm whose statistics you need.

Phil
Jan 22 '18 #2
Eman1234
12 New Member
Thank you for replying Phil! I changed it to a text box and changed the formula to Date(), but it is returning an #Error value. I am now going to try the 2 box method. I am going to use a query to do "between [start date] and [end date]" as criteria. Any idea on how to create a function that will use a lookup for the combo box of a specific firm for the date range and count how many calls?

Thanks again,

Eric
Jan 23 '18 #3
PhilOfWalton
1,430 Recognized Expert Top Contributor
Hi Eric,

We have to start gently.

Do you have a table containing at least the Firm's name and an AutoNumber filed like FirmID and the Email date?

If not, what is your table like?

Phil
Jan 23 '18 #4
Eman1234
12 New Member
The table's headings are as follows:

ID, From, Sender Name, To, Received (Date/Time), Modified (Date/Time)

Ideally, my boss wants a report where we can select the date range in the report and use a list/combo box to either select all employees or a specific employee. Then, he wants a text box that counts the # of emails received between a specific date and for that employee.

Ex. John Smith received 20 emails for the week 1/1/2018-1/5/2018

Much appreciated,

Eric
Jan 23 '18 #5
PhilOfWalton
1,430 Recognized Expert Top Contributor
That looks quite hopeful, Eric

Can you clarify what data is in "From" and what is in "Sender Name". I presume one is the Email Address.

Where does the "Employee" fit into the picture?

Phil
Jan 23 '18 #6
Eman1234
12 New Member
Well, your optimism gives me hope.

We can avoid "From" because it is so similar to "Sender Name", but "Sender Name" is just a list of employee names, which is what he wants in the drop-down. "Sender name" seems to be a mix of both names and email addresses. Sorry I didn't specify that earlier.

Eric
Jan 23 '18 #7
PhilOfWalton
1,430 Recognized Expert Top Contributor
Sorry, More questions.

Are you only interested in Emails from your Employees for this exercise, if so, how are you filtering them from your Outlook Folder?

Phil
Jan 23 '18 #8
Eman1234
12 New Member
No problem at all...ask away!

In Outlook, there is a folder that I was given administrative access to which contains the emails sent (up to 45 days of archives) from all of the employees in our team (about 150 people in our team). I created a table link between Access and Outlook, so everything in the table was imported by Access directly from the Outlook folder that I mentioned previously.

Eric
Jan 23 '18 #9
PhilOfWalton
1,430 Recognized Expert Top Contributor
Hi Eric.

Well we've done the difficult part - extracting the information from you. The rest is easy.

Assuming you have a link to your oulook folder, I suggest you create 2 tables, and append the data to them so that there is no possibility of corrupting Outlook.
The TblContacts will hold only 1 copy of the Employee Name.



The TblMessages will contain a unique combination of Employee, Subject & Date


Set up the relationship between the 2 ContactIDs

Then build a continuous form like this:



In the examples below, my Outlook Folder is called Mike.
This is the append query to add the contacts.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TbContacts ( ContactName )
  2. SELECT DISTINCT Mike.From
  3. FROM Mike;
  4.  
And this the query to append the messages
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TbdMessages ( ContacID, Subject, DateReceived )
  2. SELECT TbContacts.ContactID, Mike.Subject, Mike.Received
  3. FROM Mike INNER JOIN TbContacts ON Mike.From = TbContacts.ContactName;
  4.  
Below is all the code in the form which allows you to filter on a name or date range of combination of name & date range:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4.     Dim Fltr As String
  5.  
  6. Private Sub ApplyFilt_Click()
  7.  
  8.     Dim FDate As Date
  9.     Dim TDate As Date
  10.  
  11.     If IsNull(FromDate) And IsNull(ToDate) Then
  12.         If Nz(CboContact) > 0 Then
  13.             Fltr = "ContactID = " & CboContact
  14.         End If
  15.         GoTo FilterIt
  16.     End If
  17.  
  18.     If IsNull(CboContact) Then
  19.         If Not IsNull(FromDate) Then
  20.             FDate = CDate(Format(FromDate, "mm/dd/yy"))
  21.             If IsNull(ToDate) Then
  22.                 TDate = DateAdd("d", 1, FromDate)          ' Add 1 day
  23.                 TDate = CDate(Format(TDate, "mm/dd/yy"))
  24.                 Fltr = "DateReceived Between #" & FDate & "# And #" & TDate & "#"
  25.             Else
  26.                 TDate = DateAdd("d", 1, ToDate)          ' Add 1 day
  27.                 TDate = CDate(Format(TDate, "mm/dd/yy"))
  28.                 Fltr = "DateReceived Between #" & FDate & "# And #" & TDate & "#"
  29.             End If
  30.         End If
  31.         GoTo FilterIt
  32.     Else
  33.         If Not IsNull(FromDate) Then
  34.             FDate = CDate(Format(FromDate, "mm/dd/yy"))
  35.             If IsNull(ToDate) Then
  36.                 TDate = DateAdd("d", 1, FromDate)          ' Add 1 day
  37.                 TDate = CDate(Format(TDate, "mm/dd/yy"))
  38.                 Fltr = "ContactID = " & CboContact & " AND DateReceived Between #" & FDate & "# And #" & TDate & "#"
  39.             Else
  40.                 TDate = DateAdd("d", 1, ToDate)          ' Add 1 day
  41.                 TDate = CDate(Format(TDate, "mm/dd/yy"))
  42.                 Fltr = "ContactID = " & CboContact & " AND DateReceived Between #" & FDate & "# And #" & TDate & "#"
  43.             End If
  44.         End If
  45.         GoTo FilterIt
  46.     End If
  47.  
  48.  
  49. FilterIt:
  50.     Me.Filter = Fltr
  51.     Me.FilterOn = True
  52.  
  53.     RecCount = Me.RecordsetClone.RecordCount
  54.  
  55. End Sub
  56.  
  57. Private Sub Form_Load()
  58.  
  59.     RecCount = Me.RecordsetClone.RecordCount
  60.  
  61. End Sub
  62.  
  63. Private Sub FromDate_AfterUpdate()
  64.  
  65.     If IsNull(ToDate) Then
  66.         ToDate = DateAdd("d", 1, FromDate)          ' Add 1 day
  67.         ToDate = DateAdd("s", -1, ToDate)           ' Take off 1 second to return toi previos day
  68.     End If
  69.  
  70. End Sub
  71.  
  72.  
Phil
Jan 24 '18 #10

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

Similar topics

1
2967
by: Dan Leeder | last post by:
stroccur = DCount("", "empnotes", " = " & Chr(34) & Me.Rpt_Card_Type & Chr(34) & " And = " & Me.SSN & " And #" & & "# > " & DateSerial(Year(Me.datetime) - 1, Month(Me.datetime), Day(Me.datetime))) I'm using the above function to count similar records that have fallen in the last year. Ex: SSN datetime cattype # of records in last year
3
9271
by: psuaudi | last post by:
I am trying to use the following code, but I think there is an error in my syntax: Count = DCount("", "Change Dates", " = '" & !! & "' AND CVDate(Int( #" & & "# )) = #" & (Date) & "#") I believe that this is the particular problem area: CVDate(Int( #" & & "# )) I've been messing with this for awhile now and it's just not working properly.
1
5135
by: akirekab | last post by:
I am using DCount, but I am not able to find how to set simple multiple criteria. Here is sample of what i need. =DCount("PatientProfileID","qryFaceToFaceReason_EAP_VG","FaceToFaceReasonID=2" Or "FaceToFaceReasonID=0") Any help in syntax or formatting would be appreciated. Note if I just enter ther first criteria it works fine. I was hoping the OR could be used one way or another.
1
1821
iBasho
by: iBasho | last post by:
Hi I am using the DCount function to check and alert users for existing IDs in my database after a new record is entered. ..Private Sub CARDID_AfterUpdate() If DCount("*", "", " = '" & Me. & "'") Then MsgBox "This card ID number already exists in the system. Once you enter the dependent code you will be able to determine if this is a subsequent reinbursement submission from the same member or a new submission from another subscriber on the...
2
10440
by: trinismooth | last post by:
Hi All Trying to do a dcount with multiple criteria for example: =DCount("","access rights"," = 'kev'" and ='Christian Fellowship members temp'" And ='yes'") Thanks for any assistance
1
1828
by: Manuel Baptista | last post by:
Good afternoon, I am attempting to count those records within a data base that do not match one variable answer in a given field. To put it more clearly, I want to count the companies in a database that are headquartered in several several countries except one, namely Portugal. What is the Dcount function formula that must be used? Best reagards, Manuel Baptista
12
4783
doma23
by: doma23 | last post by:
Hi, I have the following code that doesn't work: DCount("*", "", _ "((='" & Form_frmMain.cmbField1 & "') AND (" & "='" & Form_frmMain.cmbField2 & "') AND (" & "='" & Form_frmMain.cmbField3 & "') AND (" & "='" & Form_frmMain.cmbField4 & "') AND (" & "=#" & Form_frmMain.txtField5 & "#))") > 0 Field5 is formated as a date in database. I got the run-time error 3075 (syntax error in date in query expression...) when I run this.
3
12253
by: slenish | last post by:
Hello All, I am trying to use the DCount Function to count blank records on a table from a form. I want to make it so i can press a button and the function will run and show the total in a text box on a form. I can get it to work with non null or non blank fields but for some reason it just keeps showing me 0 when i try to get it to count blank fields. If the DCount function is not the best approach I appreciate any other alternatives. FYI I...
4
5280
by: DANNYOCEAN | last post by:
I have a code that sucessfully calculates how many numbers are lower than for example 45 , for large sample number list. But i´m looking for a code that have a COUNT function with MULTIPLE CRITERIA such as, for example: i wanna know which are the numbers and how many of them follow the MULTIPLE CRITERIA: OR OR OR and so on until the final element ... OR . So the MULTIPLE CRITERIA is: { OR OR OR ... OR } i try to put the...
2
2354
by: BHudson | last post by:
Can someone help me. why does my dcount function on a text box in a report gives me a zero count when there is clearly 2 employee records in the query that has the number 1 in the heart trainee field. field record i am counting is Employee No query name is Q-Detail for Monthly S01 and the field on query with the criteria is heart trainee. =DCount("","Q-Detail for Monthly S01",=1)
0
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6198
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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 we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.