הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, December 15, 2012 8:45 PM
I've been able to sort with one method using columns of text, but seems it doesn't work the same with date/time values. I can't find a solution anywhere that'll give me what I'm after.
Anyway, what I have is this:
I have a column in my MS Access database that stores the date as "MMMM d, yyyy" (ie. January 1, 2013). I have one listbox that contains the month (listbox1), and another that contain years (listbox2). I want to create a function that will sort the column of dates that contains the name of the month from listbox1, and the year in listbox2.
So for instance, let's say the date column contains January 1, 2013 through to March 31, 2013. I then select January from Listbox1, and 2013 from Listbox2, then click a button to display all results from January 1, 2013 through to January 31, 2013 in the datagridview.
If anyone has a link they can provide me, or a solution to solve this I would appreciate it.
Thank you!
All replies (12)
Sunday, December 16, 2012 3:49 PM ✅Answered
LA,
I put together a small database that only has a name and a birthday for this example. Have a look:
I have the code on a page of my website here and I hope it helps. :)
Please call me Frank :)
Monday, December 17, 2012 1:46 AM ✅Answered
Thought I'd put this option out there too:
Private Sub BtnStatQry_Click(sender As System.Object, e As System.EventArgs) Handles BtnStatQry.Click
DBBindingSource.Filter = "Date >= #" & DTPQry1.Text & "# and Date <= #" & DTPQry2.Text & "#"
TB.Text = DBDataGridView.Rows.Count
End Sub
I used two datetimepicker controls to select a range of dates, which really isn't much different than selecting from dropdowns with months and years in it.
The other textbox at the bottom of the code is meant to simply show how many records appear for that period. I will be doing a number of functions like this for the rest of my project. I've been exporting from the datagridview into Excel and using formulas to produce these results, but I figure I'd just make the entire app self-sufficient without the use of other datalibraries.
Your code was fun seeing as I hadn't used radio buttons before so that was a good experience for me lol.
Saturday, December 15, 2012 9:02 PM
Have a look at something that I posted earlier today:
That has nothing to do with dates, but that might give you an idea of how you might go about setting it up. In LINQ, you would create a query which would return all DataRows where the criteria was at or above the minimum date AndAlso at or below the maximum date.
Please call me Frank :)
Saturday, December 15, 2012 9:35 PM
Thanks Frank! I have to walk away from my project for a bit, but I'll try out your code later, see if this or a similar idea will work for me and get back to you. Until then, I'm open to other suggestions from anyone else too.
Sunday, December 16, 2012 1:28 AM
Thanks Frank! I have to walk away from my project for a bit, but I'll try out your code later, see if this or a similar idea will work for me and get back to you. Until then, I'm open to other suggestions from anyone else too.
I hope it helps. :)
If you need me to, tomorrow I'll put together a more specific example - but that one came to mind for obvious reasons.
Please call me Frank :)
Sunday, December 16, 2012 12:21 PM
Hi Frank,
Your code works if I had the data in two separate columns, but what I'm trying to do is filter data from only one column. I basically need to find the Month and Year based on the selection from two listboxes and filter all entries with that month and year. Below is the effect I'm looking for.
I'll play around with what you've given me and maybe come up with something on my own in the meantime, but if you can help come up with something more specific to my case that would be great.
Thank you!
Sunday, December 16, 2012 2:41 PM
Let me see what I can come up with to emulate what you're doing.
Please call me Frank :)
Sunday, December 16, 2012 3:53 PM
Wow that was quick...
I'll try it when I return. I have to step out for a bit, but thanks for helping so quickly! I'll mark as answer if it works for me (likely will, looks promising at first glance).
Sunday, December 16, 2012 4:01 PM
Wow that was quick...
I'll try it when I return. I have to step out for a bit, but thanks for helping so quickly! I'll mark as answer if it works for me (likely will, looks promising at first glance).
Well I did it in a hurry so don't be surprised to find some mistakes along the way! ;-)
Please call me Frank :)
Sunday, December 16, 2012 4:52 PM
Like I said, I was in a hurry...
Please call me Frank :)
Monday, December 17, 2012 12:20 AM
That'll do just fine! Thanks Frank! Does exactly what I want.
Have a great day!
Monday, December 17, 2012 12:25 AM
That'll do just fine! Thanks Frank! Does exactly what I want.
Have a great day!
Glad it helped.
Please call me Frank :)