Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    default value for combo box (2000)

    Hi, I have a combo box (cboEvent) whose row source is a query. I have column count as3, though only displaying columns 1 and 3. The bound column is column 1. I'd like to have an AfterUpdate event that sets the default value of another combo box CategoryID to be column 3 of cboEvent. Here's the code I've been trying, however it won't set the default value to column 3 (it stays blank):

    Private Sub cboEvent_AfterUpdate()
    Me!CategoryID.DefaultValue = cboEvent.Column(3)
    End Sub

    This only results in any new record being populated with the value from column 3. I am trying to set the default for just the current record only. Can anyone help me?

    Regards
    Roger

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: default value for combo box (2000)

    Try changing:
    Me!CategoryID.DefaultValue = cboEvent.Column(3)
    to
    Me!CategoryID.DefaultValue = cboEvent.Column(2)

    The column index starts at 0, not 1.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: default value for combo box (2000)

    Are you sure it the Default value that you actually want to set ?

    The default value is what get puts into new records. Once a record exists, the default value does nothing.

    It sounds to me like you want to set the value of the control, rather than its default value.

    To do that put this code in the after -update event for the combo

    Me![CategoryID] = me![cboEvent].Column(2)
    Regards
    John



  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: default value for combo box (2000)

    >> I am trying to set the default for just the current record only.

    Do you really mean the default value, or do you want to set the value of the combo box for the current record? If so, omit .DefaultValue from the code. And heed Pat's remark: the column index is zero-based, so the first column is Column(0) etc.

  5. #5
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Christchurch
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: default value for combo box (2000)

    thanks everyone, I've got this working now. Sorry for the confusion around my use of "default" which was misleading, I couldn't think how to put it better, I was simply wanting to set a possible (and most likely) value which could also be over-ridden by the user.

    Cheers,
    Roger

Posting Permissions

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