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

Date Ranges

5
Hello,
I am very new to VBA and have a problem. I want to be able to pull an Access report only within a certain date range. I have a "DateFrom" and "DateTo" set up as text boxes in my form, but I don't know how to set them up as dates. The report is called REPORT_CARD_DATA, and so far, I've been able to create combo boxes that narrow down the information by TaxID and Names. I want to be able to narrow it down further by giving a date range (DATE_OF_EVENT). Here is my code for the combobox (this is the second one - narrows by name based on TaxID....the first combobox i just made in the form wizard...newbie in the strictest sense), but I'm clueless as far as setting up 2 textboxes that provide a range. Any help will be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.   cboProvName.Enabled = False
  4.   txtDateFrom.Enabled = False
  5.   txtDateTo.Enabled = False
  6.   txtDxFrom.Enabled = False
  7.   txtDxTo.Enabled = False
  8.  
  9.  
  10. End Sub
  11.  
  12.  
  13. Public Sub cboProvName_Select()
  14.   With Me![REPORT_CARD_DATA]
  15.     .RowSource = "SELECT [last name], [first name], [middle name] " & _
  16.                  "FROM REPORT_CARD_DATA " & _
  17.                  "WHERE [TAXID] = cboTaxID.txt"
  18. End Sub
Jun 29 '07 #1
6 1372
ADezii
8,834 Expert 8TB
Hello,
I am very new to VBA and have a problem. I want to be able to pull an Access report only within a certain date range. I have a "DateFrom" and "DateTo" set up as text boxes in my form, but I don't know how to set them up as dates. The report is called REPORT_CARD_DATA, and so far, I've been able to create combo boxes that narrow down the information by TaxID and Names. I want to be able to narrow it down further by giving a date range (DATE_OF_EVENT). Here is my code for the combobox (this is the second one - narrows by name based on TaxID....the first combobox i just made in the form wizard...newbie in the strictest sense), but I'm clueless as far as setting up 2 textboxes that provide a range. Any help will be greatly appreciated.

Private Sub Form_Load()

cboProvName.Enabled = False
txtDateFrom.Enabled = False
txtDateTo.Enabled = False
txtDxFrom.Enabled = False
txtDxTo.Enabled = False


End Sub


Public Sub cboProvName_Select()
With Me![REPORT_CARD_DATA]
.RowSource = "SELECT [last name], [first name], [middle name] " & _
"FROM REPORT_CARD_DATA " & _
"WHERE [TAXID] = cboTaxID.txt"
End Sub
I've written sample code for you to point you in the right direction. Any other questions, feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Dim MySQL As String
  2.  
  3. If IsDate(Me![txtDateFrom]) And IsDate(Me![txtDateTo]) Then
  4.  Me![REPORT_CARD_DATA].ColumnCount = 4
  5.  Me![REPORT_CARD_DATA].BoundColumn = 1
  6.  Me![REPORT_CARD_DATA].ColumnWidths = ";;;"     'Use Default Widths
  7.   MySQL = "Select [last name], [first name], [middle name], [DATE_OF_EVENT] From REPORT_CARD_DATA  Where [DATE_OF_EVENT]"
  8.   MySQL = MySQL " Between #" & Me![txtDateFrom] & "# And #" & Me![txtDateTo] & "#;"
  9.     Me![REPORT_CARD_DATA].RowSource = MySQL
  10. Else
  11.   'do nothing
  12. End If
Jun 30 '07 #2
neeZy
5
thank you very much!

I have a final question:

Once I have the form filled out (TaxID, Name, and Date Range), how do i generate a report based on my selection?

Let me explain further - REPORT_CARD_DATA is a table i have in Access that has information on how several individuals are performing (revenue generated, etc). Some people share the same tax id, while some people do not - that's why i had to add the "name" part to my form. After a tax id and name are selected, I also want to be able to pull up a date range to judge performance on.

Now, I would like to put a button on my form called "generate report" that spits out the information for that one person once pushed.

Any help will be appreciated.
Jul 2 '07 #3
shiznaw
29
I've written sample code for you to point you in the right direction. Any other questions, feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Dim MySQL As String
  2.  
  3. If IsDate(Me![txtDateFrom]) And IsDate(Me![txtDateTo]) Then
  4.  Me![REPORT_CARD_DATA].ColumnCount = 4
  5.  Me![REPORT_CARD_DATA].BoundColumn = 1
  6.  Me![REPORT_CARD_DATA].ColumnWidths = ";;;"     'Use Default Widths
  7.   MySQL = "Select [last name], [first name], [middle name], [DATE_OF_EVENT] From REPORT_CARD_DATA  Where [DATE_OF_EVENT]"
  8.   MySQL = MySQL " Between #" & Me![txtDateFrom] & "# And #" & Me![txtDateTo] & "#;"
  9.     Me![REPORT_CARD_DATA].RowSource = MySQL
  10. Else
  11.   'do nothing
  12. End If
Would it be simplier if he were to simply create a query and set the dates of the query to parameters / fields on the form? or no?
Jul 3 '07 #4
neeZy
5
Would it be simplier if he were to simply create a query and set the dates of the query to parameters / fields on the form? or no?
That would definitely be more user friendly. It's just that I'm heavily reliant on the wizard, so the best way for me was to create a form using it. The last thing I want done is to have a button call up the specifics of a table I have in Access, but alas, no wizard for that x.x Think you can help me out?

Thanks for your time
Jul 3 '07 #5
NeoPa
32,556 Expert Mod 16PB
Would it be simpler if he were to simply create a query and set the dates of the query to parameters / fields on the form? or no?
Pros: Less coding.
Cons: Query not very portable.
Query not reusable with other forms.
At the end of the day you make your own choices suited to your own situation.
Jul 3 '07 #6
ADezii
8,834 Expert 8TB
Would it be simplier if he were to simply create a query and set the dates of the query to parameters / fields on the form? or no?
Yes it would, and thanks for pointing it out to me. I'm afraid that I have gotten Post Response mixed up - happens as you get older!
Jul 5 '07 #7

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

Similar topics

2
by: Maksim Kasimov | last post by:
there are few of a time periods, for example: 2005-06-08 12:30 -> 2005-06-10 15:30, 2005-06-12 12:30 -> 2005-06-14 15:30 and there is some date and time value: 2005-06-11 12:30 what is the...
2
by: bobb | last post by:
Is there a way to select count(*) by grouping by date, and having multiple date ranges? combining... select field,count(*) from table where datefield > 2004/1/1 and datefield < 2004/1/31 and...
7
by: Thomas R. Hummel | last post by:
Hello all, I am trying to write a query that compares a member's enrollment period with the products that their group has had during that period (all members belong to a group and the products...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
2
by: junkaccount | last post by:
Hello, Using Access 2000 I would like to create one report that returns sales data for various date ranges input by the user i.e. weekly, monthly, etc. This report is bound to a query that pulls...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
4
by: norma.j.hildebrand | last post by:
I have a database that has a field (performance standard), every year the standard changed which was not a problem since we start out each year with a blank database and just change the standards...
10
by: kyosohma | last post by:
Hi, I am working on a timesheet application in which I need to to find the first pay period in a month that is entirely contained in that month to calculate vacation time. Below are some example...
16
by: Alex30093 | last post by:
OK This is my 1st post to any forum, but I rely on forums all the time. Short story is I find myself needing to become a Access DBA for work. Situation: I want to use one table of events that...
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.