View Single Post
  #2  
Old November 17th, 2004, 11:04 AM
Nikos Yannacopoulos
external usenet poster
 
Posts: n/a
Default

Lisa,

To begin with, I would add two textboxes on the form (called, say, txtDateFm
and txtDateTo, formatted as date - same format as the date field in the
table), and set their Visible property to No in form design. These will be
used for holding the from and to dates, populated by the listbox (while
still invisible) on every other choice, and made visible to be filled
manually when custom is selected.

The query for the records would reference these two text boxes in its
criterion on the date field, like:

= Forms![Form Name]![txtDateFm] and = Forms![Form Name]![txtDateTo]


I would use the double click event of the listbox (assumed name List0) to
calculate the dates and requery the subform (assumed name: Subform1) with
the records. Of course, when custom is selected, the user has to enter the
dates and then somehow requery the subform. For this I would use a command
button (called Command2 in my sample code, caption something like Refresh or
Get Data, also hidden in the form design) which is toggled between visible
and invisible together with the textboxes.

Here's the code behind the Command2 button:

Private Sub Command2_Click()
Me.Subform1.Requery
End Sub

And, finally, here's the code behind the listbox's double click event:

Private Sub List0_DblClick(Cancel As Integer)
Select Case Me.List0
Case "Today"
Me.txtDateFm = Date
Me.txtDateTo = Date
Me.Subform1.Requery
Case "This Week"
dt = Date
If Weekday(dt, 3) = 7 Then dt = dt + 7
Me.txtDateFm = dt - Weekday(dt, 3)
Me.txtDateTo = dt - Weekday(dt, 3) + 6
Me.Subform1.Requery
Case "This Month"
Select Case Month(Date)
Case 12
y1 = Year(Date)
m1 = Month(Date)
y2 = y1 + 1
m2 = 1
Case Else
y1 = Year(Date)
m1 = Month(Date)
y2 = y1
m2 = m1 + 1
End Select
Me.txtDateFm = DateSerial(y1, m1, 1)
Me.txtDateTo = DateSerial(y2, m2, 1) - 1
Me.Subform1.Requery
Case "Last Week"
dt = Date
If Weekday(dt, 3) = 7 Then dt = dt + 7
Me.txtDateFm = dt - Weekday(dt, 3) - 7
Me.txtDateTo = dt - Weekday(dt, 3) - 1
Me.Subform1.Requery
Case "Last Month"
Select Case Month(Date)
Case 1
y1 = Year(Date) - 1
m1 = 12
y2 = y1 + 1
m2 = 1
Case Else
y1 = Year(Date)
m1 = Month(Date) - 1
y2 = y1
m2 = m1 + 1
End Select
Me.txtDateFm = DateSerial(y1, m1, 1)
Me.txtDateTo = DateSerial(y2, m2, 1) - 1
Me.Subform1.Requery
Case "Custom"
Me.txtDateFm = Null
Me.txtDateTo = Null
Me.txtDateFm.Visible = True
Me.txtDateTo.Visible = True
Me.Command2.Visible = True
GoTo skip_hide
End Select

Me.txtDateFm.Visible = False
Me.txtDateTo.Visible = False
Me.Command2.Visible = False

skip_hide:
End Sub

Don't forget to change the object names to your real names!

HTH,
Nikos

"RusCat" wrote in message
...
Good morning,

Here is something I'm tryng to do, but can't seem to get a handle on. I

am
hoping for some direction.

I have the following things listed in a listbox: today, this week, this
month, last week, last month, custom

I want to be able to click on THISWEEK and have all the records for this
week to show up on my form.

It is a projects table where our employees log in the hours they have

spent
on a project. I need them to be able to see the data by the choices

above.

ALSO: how would I create a CUSTOM set of data? Click on CUSTOM, some

sort
of boxes appear where I could type in the 2 dates and everything between
those dates would show up on the form.

I've tried queries, but I'm just not getting it. I understand the logic
behind it, but just not how to get it done. I'm a novice Access user, so
please be gentle in your help and explainations !!

Thank you so much.
LisaB.