|
-
Feb 16th, 2005, 07:56 AM
#1
Thread Starter
New Member
Sorting Dates
Hi,
I am wondering if anyone could help me.
I am using a DataGrid to display employee expenses. Each Expense has an "Incurred_Date". A the moment my grid shows all the expenses for a particular employee.
How do I go about showing an employee's expenses just for one month??
I have a dropdown list with the 12 months of the year and was thinking that if i click on a month, it would compare it to the database and then display the necessary data.
If someone could show me some sample code I would really appreciate it.
Thank You!
-
Feb 16th, 2005, 08:11 AM
#2
Fanatic Member
Re: Sorting Dates
How are you populating the datagrid now?
Chris
Master Of My Domain
Got A Question? Look Here First
-
Feb 16th, 2005, 09:27 AM
#3
Thread Starter
New Member
Re: Sorting Dates
Not sure if this is what you mean but this is my code!
strSQL = "SELECT Expenses.EmpID,Expenses.ExpID, Expenses.Date_Incurred, Expenses.RateID, Rates.Description, Expenses.Mileage, Expenses.Total_Cost FROM Expenses INNER JOIN Rates ON Expenses.RateID = Rates.RateID WHERE EmpID = " & empExp & " "
cmdComm.ActiveConnection = conConnect
cmdComm.CommandText = strSQL
Dim rs As New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open strSQL, conConnect
ident = "" & rs!EmpID
If ident Is Nothing Then
MsgBox "There is no such Record! Enter another I.D.", vbInformation, "No Record"
Else
Set dgdExpAd.DataSource = rs 'was rstRec
dgdExpAd.ReBind
'Display the results on the grid
dgdExpAd.Visible = True
End If
-
Feb 16th, 2005, 09:45 AM
#4
Re: Sorting Dates
Ok. Then unless I'm missing something it would seem that you could get what you wanted but adding an AND to your SQL. Something like
VB Code:
strSQL = "SELECT Expenses.EmpID,Expenses.ExpID, Expenses.Date_Incurred, "
strSQL = strSQL & "Expenses.RateID, Rates.Description, Expenses.Mileage, "
strSQL = strSQL & "Expenses.Total_Cost "
strSQL = strSQL & "FROM Expenses INNER JOIN Rates ON Expenses.RateID = Rates.RateID "
strSQL = strSQL & "WHERE EmpID = " & empExp & "
strSQL = strSQL & "AND datefield BETWEEN #startdate# AND #enddate# "
cmdComm.ActiveConnection = conConnect
cmdComm.CommandText = strSQL'etc
How you would encapsulate your two dates would depend on the DB field types (i.e., depending on whether your date field is text or date/time)
PS: I broke your sql statement into different lines simply to make it easier to read in this forum thread. That isn't something you necessarily have to do in your code.
-
Feb 16th, 2005, 10:34 AM
#5
Thread Starter
New Member
Re: Sorting Dates
Thanks for your help..
I am nit getting an error but my grid is just not showing any detail! This is my SQL statement.
strSQL = "SELECT Expenses.EmpID,Expenses.ExpID, Expenses.Date_Incurred, Expenses.RateID, Rates.Description, Expenses.Mileage, Expenses.Total_Cost FROM Expenses INNER JOIN Rates ON Expenses.RateID = Rates.RateID WHERE EmpID = " & empExp & ""
strSQL = strSQL & " AND Expenses.Date_Incurred BETWEEN " & DTPicker2.Value & " AND " & DTPicker1.Value & " "
As I am usind date pickers, do i need to change the way the date puts its values into the data base..I am using date/time types
-
Feb 16th, 2005, 10:44 AM
#6
Re: Sorting Dates
I went back through everything that had been posted and couldn't see where what kind of database you are using was mentioned. How you deal with dates if different between Microsoft product (SQL Server and Access) and Oracle.
I'm going to make the assumption you are using a Microsoft product when I make the suggestion to encapsulate your datepicker values in # signs. See if that works.
-
Feb 16th, 2005, 10:44 AM
#7
Fanatic Member
Re: Sorting Dates
Try this:
strSQL = strSQL & " AND Expenses.Date_Incurred BETWEEN " & "#" & DTPicker2.Value & "# AND #" & DTPicker1.Value & "#"
-
Feb 16th, 2005, 12:50 PM
#8
Thread Starter
New Member
Re: Sorting Dates
Thank you so much..that worked a charm. Legends!
-
Feb 16th, 2005, 12:53 PM
#9
Re: Sorting Dates
Cool!
Please edit your first post, and add {RESOLVED} to the original text of the subject line, and then add the green checkmark icon.
By the way: Welcome to the forums.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|