Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2014

    Unanswered: Having a combo box's default value refer to another combo box?

    I'm creating a database for time off tracking, and I have a form with a checkbox and three combo boxes.

    The first combo box is cboPTODate, the second is cboStartDate and the third is cboEndDate.

    The checkbox is chkMultiDays. The checkbox defaults to being unchecked, and when it is unchecked, only one field (combo box) is active and visible: cboPTODate.

    Basically, if an associate is off for only one day, they enter the value in cboPTODate. If they are off for more than one day, they check the checkbox, and the combo boxes for start and end date become visible and active.

    Combo boxes cboPTODate and cboStartDate have the same control source - a column cunningly labeled "StartDate" in my actual table. cboEndDate's control source is the "EndDate" table.

    What I want is for cboPTODate to feed into both the StartDate and EndDate columns - so if someone is only off for one day, the Start and End dates in the table should match. I'm really not sure how best to do this, and was wondering if anyone had any suggestions?

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    what you could try is:-
    place some code behind the checkbox
    depends on what the checkbox represents, and how you have implemented it, my understanding is that if checked then a user can select a start and end date
    so in the check box's on click event:-
    if chkMultiDays.value = true then 'the user is registering a start AND end date
    cboEndDate.enabled = true
    cboEndDate.enabled = false
    you'd probably want to force the checkbox to be single day when you enter a new recrd
    in the forms before insert event
    chkMultiDays.value = false
    cboEndDate.enabled = false

    when a user selects a date in the start date combo box
    if chkmultidays.value = true then
    'check we don't have a comedian trying to enter a start date after the end date
    if cboStartDate > cboEndDate then
    'we could paly nice and swap the values
    'we could get stroppy and insist they stop messign around
    'its your app, so what rule do you want applied
    else 'the user is only entering a single day off, so force the dates to be the same
    cboEndDate.value = cbostartDate.value

    you almost certainly want to tweka the logic to cover all permutations of the UI
    and a user enterign data as they see fit
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2014
    Just an fyi, I've tried:

    Setting cboEndDate's default value "= [cboPTODate]" and then having:

    Private Sub cboPTODate_AfterUpdate()
    End Sub

    This doesn't update the table with the information.

    Neither does

    Private Sub cboEndDate_BeforeUpdate()
    if cboPTODate.Visible = True Then
    cboEndDate.Value = cboPTODate.Value
    End if
    end sub

  4. #4
    Join Date
    Jul 2014
    The code behind the checkbox is as follows:

    Private Sub chkMultiDay_AfterUpdate()
    If chkMultiDay = True Then
    cboStartDate.Visible = True
    cboStartDate.Enabled = True
    cboEndDate.Visible = True
    cboEndDate.Enabled = True
    chkPartialDay.Enabled = False
    chkPartialDay.Visible = False
    cboPTODate.Visible = False
    cboPTODate.Enabled = False
    cboStartDate.Visible = False
    cboStartDate.Enabled = False
    cboEndDate.Visible = False
    cboEndDate.Enabled = False
    chkPartialDay.Enabled = True
    chkPartialDay.Visible = True
    cboPTODate.Visible = True
    cboPTODate.Enabled = True
    End If

    I attempted to put the values in there, but it still doesn't feed into the table. I'd prefer the checkbox to default to being unchecked, as most times, associates only take one day off, and (sad as this sounds) I'd prefer to have a little bit less confusion, as I know people will put in start and end dates if they see them, rather than checking off the box to indicate they'll only be out for one day.

    Edited to say: I definitely want to force the users to enter the appropriate start and end dates, as you indicated. Luckily, this is for use by managers and up only, so the likelihood of a joker is slim, although the likelihood of a rather harried/busy manager is pretty high.

    If I'm reading what you've said correctly, then because I'm disabling the field, the value won't update - is this something I could get around by simply removing:
    If chkMultiDay = True Then
    cboEndDate.Enabled = True
    cboEndDate.Enabled = False

    If so, it would be enabled, but still invisible, and thus it...could update with the start date value?
    Last edited by Cieren; 07-28-14 at 14:13.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts