A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Two Linked Combo Boxes



 
 
Thread Tools Display Modes
  #1  
Old December 27th, 2006, 03:55 PM posted to microsoft.public.access.forms
Sprinks
external usenet poster
 
Posts: 531
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:44 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.