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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box additem 1

Status
Not open for further replies.

spizotfl

MIS
Aug 17, 2005
345
US
hi, i have a combo box on a form that will be used to open reports. the combo box has years in it. i want to check when the form opens if the current year is listed as an option, if not, i want to add it to the top of the list. i can manage that just fine. the problem is that if i comment out the code, the value that was "added" is no longer in the list. in 2006, 2005 will no longer be listed in the combo box. in 2007, 2006 won't be listed. is there a way to make these values persist?
Code:
Private Sub Form_Open(Cancel As Integer)
    Dim x As Integer
    x = cmbYear.ListCount
    If (cmbYear.ItemData(0) = CStr(Year(Now()))) Then
        Exit Sub
    Else
        cmbYear.AddItem Item:=CStr(Year(Now())), Index:=0
    End If
    
End Sub
 
Dim x As Integer
x = Val(cmbYear.ItemData(0))
While x < Year(Now)
cmbYear.AddItem Item:=CStr(x + 1), Index:=0
x = x + 1
WEnd

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top