Combo Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have records that contain an entry date. I wish to set up a form for
displaying all records that were entered on the same date.

I would like a combo box to have a list of available dates and allow the
user to select one date and then display all the records with the matching
date.

How in the heck do I do that? I know, I'm dreaming here, but it would save
me a TON of trouble to understand how to do this.

Greg
The oft Access confused
 
Set these properties for your combo:
Name cboFilterDate
Control Source {leave this blank!}
Format Short Date
Limit To List Yes
RowSource SELECT DISTINCT [YourDateField] FROM [YourTable] ORDER
BY [YourDateField];
After Update [Event Procedure]

Click the Build button (...) beside the After Update property. Access opens
the code window.

Private Sub cboFilterDate_AfterUpdate()
Dim strWhere As String

If Me.Dirty Then 'Save any edits
Me.Dirty = False
End If
If IsNull(Me.cboFilterDate) Then
Me.FilterOn = False 'Show all records
Else
strWhere = "[YourDateField] = " & _
Format(Me.cboFilterDate, "\#mm\/dd\/yyyy\#")
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub

Note: If the date field contains a time component (e.g. its Default Value is
"=Now()"), then you will need to use DateSerial() to grab just the date
values.
 
Back
Top