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!

VBA Combo Boxes 1

Status
Not open for further replies.

SarahMH

MIS
May 16, 2003
28
0
0
GB
Can anyone help.

I am using a version of Access that doesn't support the '.additem' function.

I wish to populate a combo box with the date and the last 6 days. I cannot use the .additem can anyone suggest what I can do?

Thanks
 
The combo and Listbox in Access are different from VB. They do not have Add or Insert methods

You can insert an activex object Microsoft Forms Combo which is the same as VB component.
In Access there is a property Row Source type. This should be set to Value List.

You have to define the Rowsource property of the ListBox
The following code should work

For i = 0 to 6
MyCombo.rowsource = MyCombo.rowsource & DateAdd("d",-1*i,date) & ";"
Next

PS: The column count property should be 1. If you have more than 1 then that many strings separated by ; should be added to rowsource

Best of luck
 
Thank you.

My solution was very similar I wrote a function;
Public Function Last7Days() As String
Dim i As Integer
Dim DT As Date
Dim SList As String


'DT is current date and the loop deducts a day each time

For i = 0 To 6 'Step -1
DT = Date - i
SList = SList & DT & ";"
Debug.Print SList
Next
Last7Days = SList
End Function
and called the function in the open form procedure:
cboRptDate.RowSource = Last7Days()

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top