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

Using dates to search query records

Michael Adams
I have a form that has two (2) calendar dates 1. fromdatetext, 2. todatetext. I would like to be able to search the records from query "Emp_Lst_Frm_Query" and give the sum results from the dates. I would like to use the "Sub_Cmd" button to activate the search. I will be commenting out the case statement so the button only does the search for the dates.

I would like to be able to put total records in TotalTxt and then populate Incident, Request, and ChangeOrder fields with the proper sums.

The calendar controls work perfect.

Here is the code for the entire form, I am currently doing things one piece at a time. Then when things are working the way I like, I then combine them.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3.  Dim Originatorcmb As ComboBox
  4.  Private Sub ocxcalendar_Click()
  5.     Originatorcmb.Value = ocxcalendar.Value
  6.     Originatorcmb.SetFocus
  7.     ocxcalendar.Visible = False
  8.     Set Originatorcmb = Nothing
  9. End Sub
  10. Private Sub fromdatecmb_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  11.  
  12.     Set Originatorcmb = fromdatecmb
  13.  
  14.     ocxcalendar.Visible = True
  15.     ocxcalendar.SetFocus
  16.     If Not IsNull(Originatorcmb) Then
  17.         ocxcalendar.Value = Originatorcmb.Value
  18.     Else
  19.         ocxcalendar.Value = Date
  20.     End If
  21. End Sub
  22. Private Sub todatecmb_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  23.     Set Originatorcmb = todatecmb
  24.  
  25.     ocxcalendar.Visible = True
  26.     ocxcalendar.SetFocus
  27.     If Not IsNull(Originatorcmb) Then
  28.         ocxcalendar.Value = Originatorcmb.Value
  29.     Else
  30.         ocxcalendar.Value = Date
  31.     End If
  32. End Sub
  33. Private Sub Sub_Cmd_Click()
  34.  
  35.     Dim typeCount As Integer
  36.  
  37.     Select Case typeCount = DCount("[workedby]", "Emp_Lst_Frm_Query", "[workedby]= '" & Me.empcmb.Value & "'")
  38.     Case Me.empcmb.Value = "1"
  39.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[workedby] = 'MJA'")
  40.         Me.TotalTxt.Value = typeCount
  41.         Me.Repaint
  42.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Incident' And [workedby] = 'MJA'")
  43.         Me.Inc_Text.Value = typeCount
  44.         Me.Repaint
  45.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Request' and [workedby] = 'MJA'")
  46.         Me.Req_Text.Value = typeCount
  47.         Me.Repaint
  48.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Change Order' and [workedby]= 'MJA'")
  49.         Me.CO_Text.Value = typeCount
  50.         Me.Repaint
  51.     Case Me.empcmb.Value = "2"
  52.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[workedby] = 'MOB'")
  53.         Me.TotalTxt.Value = typeCount
  54.         Me.Repaint
  55.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Incident' And [workedby] = 'MOB'")
  56.         Me.Inc_Text.Value = typeCount
  57.         Me.Repaint
  58.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Request' and [workedby] = 'MOB'")
  59.         Me.Req_Text.Value = typeCount
  60.         Me.Repaint
  61.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Change Order' and [workedby]= 'MOB'")
  62.         Me.CO_Text.Value = typeCount
  63.         Me.Repaint
  64.     Case Else
  65.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[workedby] = 'SLT'")
  66.         Me.TotalTxt.Value = typeCount
  67.         Me.Repaint
  68.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Incident' And [workedby] = 'SLT'")
  69.         Me.Inc_Text.Value = typeCount
  70.         Me.Repaint
  71.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Request' and [workedby] = 'SLT'")
  72.         Me.Req_Text.Value = typeCount
  73.         Me.Repaint
  74.         typeCount = DCount("[type]", "Emp_Lst_Frm_Query", "[Type] = 'Change Order' and [workedby]= 'SLT'")
  75.         Me.CO_Text.Value = typeCount
  76.         Me.Repaint
  77.     End Select
  78. End Sub
I would like to thank everyone in advance because this site has been a great resource.
Jul 20 '10 #1
8 2710
NeoPa
32,556 Expert Mod 16PB
Check out Example Filtering on a Form then, if you still have problems with it, post an explanation of where you're struggling and we can help you.
Jul 21 '10 #2
Thanks NeoPa, that was some good information, however, I am trying to filter based on a date range input by a "from" and a "to" date, an "employee name"(only three), and the "work order type". I can post the entire code here if you like, and I can try to post a picture of the form.

In my code(I am a very "NEW" person to this) I am trying to do a few different things. I will make those posts when I get to that point in the process. Currently I am trying to filter the data according to the requirements in the above paragraph.

Would you like to see the entire code? Also, again I am new to this posting stuff, what would i use for a URL if the image to the form is on my desktop?
Jul 23 '10 #3
NeoPa
32,556 Expert Mod 16PB
Michael Adams: Thanks NeoPa, that was some good information, however, I am trying to filter based on a date range input by a "from" and a "to" date, an "employee name"(only three), and the "work order type". I can post the entire code here if you like, and I can try to post a picture of the form.
That sounds very much like what the article helps with Michael. The format for date ranges (any ranges actually) is to use the Between construct. Without going into exhaustive detail (as most of the rest of it is covered in the article) date criteria in SQL would look something like :
Expand|Select|Wrap|Line Numbers
  1. WHERE ((...)
  2.   AND  ([DateField] Between #1/1/2010#
  3.                         And #12/31/2010#)
  4.   AND  (...))
As for seeing your code, I may ask for that at some point in the process, but for now we should be concentrating on the code that it should be like.

Pictures are rarely worth the effort. I have an understanding of what I need to know. If I didn't then I'd expect you to explain more clearly rather than drop a piccy in. There's only certain things where they can actually help in my view.
Michael Adams: In my code(I am a very "NEW" person to this) I am trying to do a few different things. I will make those posts when I get to that point in the process. Currently I am trying to filter the data according to the requirements in the above paragraph.
Sounds a good approach. Too many questions (>1) in a single thread can soon get everything very complicated. Feel free to post a link in here to any new threads you post that are related.
Michael Adams: Would you like to see the entire code? Also, again I am new to this posting stuff, what would i use for a URL if the image to the form is on my desktop?
No need for your code at this time.

There is almost no way (and certainly no safe way) to publish anything from your desktop to the web. This statement isn't absolute, but I think it's true enough from your perspective. Whenever you feel the need to share such a picture then use a third-party web to host it and post a link.
Jul 23 '10 #4
I am now getting a data type mismatch in criteria expression in this line code.

Expand|Select|Wrap|Line Numbers
  1. Select Case Me.cmbEmp.Value
  2.     Case "Michael J Adams"
  3.         mycount = DCount("[type]", "Emp_Lst_Frm_query", "[employee] = 'Michael J Adams' And [cudate] between '" & Me.fromdatecmb.Value & "' and '" & Me.todatecmb.Value & "'")
  4.         Debug.Print [CUDate], [Employee], [Type], mycount,[fromdatecmb], [todatecmb];
  5.         Me.TotalTxt.Value = mycount
  6.         Me.Repaint
In the debug I am getting these data returns:
[CUDate] = 5/20/2010
[Employee] = "Michael J Adams"
[Type] = "Change Order"
mycount = 0
[fromdatecmb] = 12:00:00 AM
[todatecmb] = 12:00:00 AM

I believe that is where my mismatch is. the [fromdatecmb] and the [todatecmb] in the form is not pulling in the date
Jul 23 '10 #5
I figured it out! YEAH.

Here is the final code I came up with:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.cmbEmp.Value
  2.     Case "Michael J Adams"
  3.         mycount = DCount("[type]", "Emp_Lst_Frm_query", "[employee] = 'Michael J Adams' And [cudate] between '" & Me.fromdatecmb.Value & "' and '" & Me.todatecmb.Value & "'")
  4.         Me.TotalTxt.Value = mycount
  5.         Me.Repaint
  6.         mycount = DCount("[Type]", "Emp_Lst_Frm_query", "[Type] = 'incident' and [employee] = 'Michael J Adams' and [cudate] between '" & Me.fromdatecmb.Value & "' and '" & Me.todatecmb.Value & "'")
  7.         Me.Inc_Text.Value = mycount
  8.         Me.Repaint
  9.         mycount = DCount("[Type]", "Emp_Lst_Frm_query", "[Type] = 'Request' and [employee] = 'Michael J Adams' and [cudate] between '" & Me.fromdatecmb.Value & "' and '" & Me.todatecmb.Value & "'")
  10.         Me.Req_Text.Value = mycount
  11.         Me.Repaint
  12.         mycount = DCount("[Type]", "Emp_Lst_Frm_query", "[Type] = 'Change Order' and [employee] = 'Michael J Adams' and [cudate] between '" & Me.fromdatecmb.Value & "' and '" & Me.todatecmb.Value & "'")
  13.         Me.CO_Text.Value = mycount
  14.         Me.Repaint
Jul 23 '10 #6
NeoPa
32,556 Expert Mod 16PB
Good post! We are not going to be long sorting this out if you respond as clearly and intelligently every time.

I can see in your line #3 that you are formatting your dates wrongly (See Literal DateTimes and Their Delimiters (#)). The delimiters should be hashes (#) and the date strings themselves should be formatted as m/d/yyyy.

It also appears that no dates have been selected at run-time.

This code should work, but you'd need to ensure valid dates were entered in order to test it properly :
Expand|Select|Wrap|Line Numbers
  1. mycount = DCount("[type]", _
  2.                  "Emp_Lst_Frm_query", _
  3.                  "([employee]='Michael J Adams') And " & _
  4.                  "([cudate] Between " & Format(Me.fromdatecmb,"\#m/d/yyyy\#") & _
  5.                               " And " & Format(Me.todatecmb,"\#m/d/yyyy\#"))
PS. I see you've been busy while I've been working on this. Good for you.
Jul 23 '10 #7
For the Date data I am using a calendar control which is activated by a mousedown event in each datecmb box. Will I still need to format the date in the way you suggested?
Jul 23 '10 #8
NeoPa
32,556 Expert Mod 16PB
Absolutely. It could have all sorts of ways of displaying otherwise. In your earlier post they seemed to display as times only, which would presumably format your SQL string in the same way. Not much use to you.
Jul 23 '10 #9

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

Similar topics

4
by: Lucky | last post by:
I have a vb.net windows app that connects to an access database. The database has 1 table. One of the columns is called "Address". A user enters any address into a textbox (txtValue) then clicks...
6
by: Access Newbie | last post by:
I'm using Access 2000 and I'm trying to create a pass-through query to append all the data from a local table to a remote table. I'm using the SQL query editor in MS Access to create the query (I...
1
by: SC | last post by:
I'm developing a site that may eventually have a very large database of users (hopefully, but who knows). It will be a community website where users can search each other (think Friendster,...
2
by: turbosatan | last post by:
i need to send a query from a web app to a search page on my site i understand that to use googles search i would use something along the lines of http://www.google.com/search?=q but the...
7
by: Frankie | last post by:
I'm trying to run the following search query: $query = sprintf ("SELECT itemNumber, thumbnailURL, title, description, price FROM apparel,hats WHERE apparel.title OR apparel.description OR...
1
by: vHTML | last post by:
hello everyone :) I am trying to make a page which would take a "entered" on search query from the previous page and display results in google with that query in an <iframe> in the results.htm...
2
by: fusonts | last post by:
Can someon show me how to wirte a mySQL search query to search from only the open records. This is what I have but it continues to return records that are closed so I'm obviously doing something...
3
manoj9849967222
by: manoj9849967222 | last post by:
Hi All I have a great problem. Is there a way to filter records using dates. I have a table called sales. now i want to filter record say from 1/1/2006 to 1/1/2007. which would show me the sales...
1
by: Grubsy4u | last post by:
Grubsy4u Newbie 7 Posts October 5th, 2007 11:31 AM #1 Report calculations --------------------------------------------------------------------------------
6
by: paankhate | last post by:
Hi, I have a task at hand to reduce the time taken for search query to execute. The query fetches records which will have to sorted by degrees away from the logged in user. I have a function...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.