Consulting

Results 1 to 4 of 4

Thread: Default Value in Combobox

  1. #1
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location

    Default Value in Combobox

    Hi there,

    I have the following code
    [vba]Private Sub UserForm_Initialize()
    Set ws = Worksheets("Lookups")
    Me.StartUpPosition = 0
    Me.Top = 125
    Me.Left = 125
    Me.Width = 365
    Me.Height = 396.75
    Me.DSTHeader.Width = 365
    cboWhoCalled.List = WorksheetFunction.Transpose(ws.Range("WhoCalled"))
    cboReason.List = WorksheetFunction.Transpose(ws.Range("CallReason"))
    cboSubject.List = WorksheetFunction.Transpose(ws.Range("EmailSubject"))
    cboScheme.List = WorksheetFunction.Transpose(ws.Range("Scheme"))
    cboSendTo.List = WorksheetFunction.Transpose(ws.Range("Destination"))

    Me.txtDate.Value = Format(Date, "yyyy/mm/dd")
    Me.txtTime.Value = Time
    Me.txtCM.Value = Application.UserName
    Me.txtCM.SetFocus
    cmdUpdate.Enabled = True
    End Sub[/vba]

    This all works fine, however, i now want to set the field cboSendTo to a default value. The value will be taken from the singel cell range named "SupportCM". For the life of me i can't get the field to default to that value.

    I've attached the workbook, and there are other references to this field that also change the value. I've tried adding the following into the above

    [vba]Set des = ws.Range("SupportCM")
    cboSendTo.Value = des
    [/vba]

    and changing the various references to cbSendTo accordingly, but no joy.

    Any suggestions?

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The value is a string or number, not an object, so don't Set it

    [vba]

    des = ws.Range("SupportCM").Value
    cboSendTo.Value = des
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Hi xld,

    Maybe i'm just being a bit think, but i can't get it to work :-
    [vba]Private Sub UserForm_Initialize()
    Set ws = Worksheets("Lookups")
    des = ws.Range("SupportCM").Value
    Me.StartUpPosition = 0
    Me.Top = 125
    Me.Left = 125
    Me.Width = 365
    Me.Height = 396.75
    Me.DSTHeader.Width = 365
    cboWhoCalled.List = WorksheetFunction.Transpose(ws.Range("WhoCalled"))
    cboReason.List = WorksheetFunction.Transpose(ws.Range("CallReason"))
    cboSubject.List = WorksheetFunction.Transpose(ws.Range("EmailSubject"))
    cboScheme.List = WorksheetFunction.Transpose(ws.Range("Scheme"))
    cboSendTo.List = WorksheetFunction.Transpose(ws.Range("Destination"))

    Me.txtDate.Value = Format(Date, "yyyy/mm/dd")
    Me.txtTime.Value = Time
    Me.txtCM.Value = Application.UserName
    Me.txtCM.SetFocus
    Me.cboSendTo.Value = des
    cmdUpdate.Enabled = True
    End Sub[/vba]Plus i've amended all the other references to = des also.
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

  4. #4
    VBAX Tutor phendrena's Avatar
    Joined
    Oct 2008
    Location
    Huddersfield, UK
    Posts
    285
    Location
    Anyone able to provide further assistance with this one please?

    Thanks,
    Somewhere in the dark and nasty regions where nobody goes, stands an ancient castle.
    Deep within this dank and uninviting place lives Berk, overworked servant of The Thing Upstairs.
    But thats nothing compared to the horrors that lurk beneath The Trap Door.

Posting Permissions

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