Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select date from drop down

Status
Not open for further replies.

tbac

Technical User
Jun 16, 2003
59
0
0
US
On an MS Access form, I want the user to be able to select a date from a drop down combo box that shows a range of dates from 10 days before today to 20 days in the future. Right now I have a table that has dates and I use a query that shows only dates that are 10 days before to 20 days after today. But I have to update the dates in the table regularly. There must be a way to select dates without taking the dates from a table
 
You can use some VBA in Form Open event. Assuming a combo box named cboDateRange that is set to Value List. The following code will populate the RowSource of the combo box.

Code:
Private Sub Form_Open(Cancel As Integer)
    Dim datDate As Date
    Dim strRowSource As String
    For datDate = Date - 10 To Date + 20
        strRowSource = strRowSource & datDate & ";"
    Next
    Me.cboDateRange.RowSource = Left(strRowSource, Len(strRowSource) - 1)
    
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top