Sorting Data By Date

kevsim

Registered User.
Local time
Today, 21:38
Joined
Aug 10, 2002
Messages
34
Using a form with 2 Text boxes, one for Start Date and the other for End Date and a Command button, I wish to sort and view all records when I press the command button after the start and finish dates are entered into the text boxes associated with the query. I would do this using the on click event of the command button. I have included some code that does not work. As I am not sure how to do this I would appreciate some assistance.
[T_FinalData] is the table and [DateWorkDone] is the field in the table.

Private Sub Command34_Click()
Dim SQLst, Sdate, Edate
Sdate = Text30
Edate = Text32
SQLst = "SELECT [DateWorkDone] FROM [T_FinalData]" & "WHERE [Sdate] >= DateWorkDone And [End Date]<= DateWorkDone "
End Sub
kevsim
 
Try something like this_

Private Sub Command34_Click()
Dim SQLst as string

SQLst = "SELECT [DateWorkDone] FROM [T_FinalData] WHERE [DateWorkDone] BETWEEN #" & Me!Text30 & "# And #" & Me!Text32 & "#"
..
At this point you need to do something with the SQL, eg.
me!ListBox.RowSource = SQLst
..
End Sub
 
Peter Rallings, Thanks for the info, however I am still having problems as the records will still not filter by date. I have attached the latest code, but when it comes to line "Set DateWorkDone", I receive the error, "Invalid use of property". Could you please assist me further.

Private Sub Command91_Click()
Dim SQLst As String
Dim Sdate, Edate

Sdate = Text30
Edate = Text32
SQLst = "SELECT [DateWorkDone] FROM [T_FinalData] WHERE [DateWorkDone] BETWEEN #" & Me!Text30 & "# And #" & Me!Text32 & "#"
Set DateWorkDone = CurrentDb.OpenRecordset(SQLst)
End Sub
kevsim
 

Users who are viewing this thread

Back
Top Bottom