If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Two Linked Combo Boxes
I have an unbound form that displays timesheet summary and detail data in two
subforms. Each is linked to an unbound textbox on the main form. There are two unbouund combo boxes, cboStaffID and cboPeriod, from which the user selects the staff member and period to be displayed. It's possible that when a new staff member is chosen, a record does not exist for the currently selected date, and vice versa. If it doesn't, I want to select the first item in the list. The following code works but seems cludgy. Does anyone have a better idea? ' cboStaffID AfterUpdate code Dim blnPeriodExists As Boolean Dim dtePeriod As Date Dim i As Integer 'Initialize blnPeriodExists, dtePeriod blnPeriodExists = False dtePeriod = Me![cboPeriod] With Me![cboPeriod] ' Show timesheet periods for chosen staff member .Requery ' If the date doesn't exist for this staff member, select the first one in the list For i = 0 To .ListCount - 1 If .ItemData(i) = dtePeriod Then blnPeriodExists = True Exit For End If Next i If blnPeriodExists = False Then .Value = .ItemData(0) End If End With ' Assign link for subforms Me![txtTSID] = fintGetTSID(cboStaffID, cboPeriod) Thank you. Sprinks |
Thread Tools | |
Display Modes | |
|
|