Consulting

Results 1 to 9 of 9

Thread: Solved: Loading a listBox

  1. #1
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location

    Solved: Loading a listBox

    Hi,

    I have an excel user form called 'Sell_Order' with 2 Text Boxes (called 'Client' and 'Account_No') that take values from cells A1 and K1 on the active sheet and also a listBox called 'Holdings' that has 5 columns of data coming from a named range 'Absolute' on a worksheet called 'Holdings'
    my problem is that the Boxes don't load on the first opening but if I close it and re-open it the 3 boxes load OK.

    Here is the code I have used.
    Range("A1").Select
    Sell_Order.Client.RowSource = "A1"
    Sell_Order.Account_No.RowSource = "K1"
    If ActiveCell.Value = "ABSOLUTE INVESTMENT MANAGEMENT" Then
    Sell_Order.Holdings.RowSource = "Holdings!Absolute"
    End If
    I have tried 'Initialize and Load' but still only loads on the second opening of the user form.

    I have Windows 7 Professional and Excel 14.0.473.1000 (32 bit)
    Any help would be much appreciated.
    Regards,
    Peter

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    I think we'd have to see the workbook itself.
    If it's any use, any code you want to run when the userform is first shown/loaded should be in the Initialize event.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Hi,
    Thanks for your help in advance.
    Here is my code so far.

    Regards,
    Peter

    Private Sub New_SELL_Order_UserForm_Initialize()
    Dim Client As String
    Dim Account_No As listbox
    Dim Holdings As listbox
    Dim Sell_Order_Stock_Code As String
    Dim Sell_Order_Stock_Name As String
    Dim Sell_Order_ISIN As String
    Dim Sell_Order_GTC As OptionButton
    Dim Sell_Order_Recd_Time As Date
    Dim Sell_Order_Amount As Integer
    Dim Sell_Order_Limit As Integer
    Dim Sell_Order_Instructions As String
    Dim Sell_Order_Broker As ComboBox
    Dim TextBox1 As String

    ' Call UserForm_Initialize
    'Unload Sell_Order
    'Load listbox2
    'Initialize_Sell_Order
    ' Sell_Order_Initialize
    'Sell_Order.ListBox1.AddItem ("A1")
    'Sell_Order.ListBox1.AddItem Item

    ActiveSheet.Unprotect
    Application.ScreenUpdating = True
    Sell_Order.Show
    Dim oneControl As Object
    For Each oneControl In Sell_Order.Controls
    Select Case TypeName(oneControl)
    Case "TextBox"
    oneControl.Text = vbNullString
    Case "OptionButton"
    oneControl.Value = False
    Case "ComboBox"
    oneControl.Value = ""
    End Select
    Next oneControl





    Range("A1").Select
    Sell_Order.Client.RowSource = "A1"
    Sell_Order.Account_No.RowSource = "K1"
    If ActiveCell.Value = "ABSOLUTE INVESTMENT MANAGEMENT" Then
    Sell_Order.Holdings.RowSource = "Holdings!Absolute"
    End If
    Load Sell_Order
    End Sub

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Have you got two userforms?! One called
    New_SELL_Order_UserForm
    and the other
    Sell_Order
    ??

    If you only have one userform, what's it called?
    You don't need explicitly to call the initialize event, it's triggered by showing the userform.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Hi, there should be just one - Sell_Order.

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by pcarmour
    Hi, there should be just one - Sell_Order.
    I think I need to see a version of your workbook.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Hi,
    I have attached my spreadsheet 'Test'.
    If you go to tab Absolute and click 'New Sell Order' the user form opens empty, click cancel or close and then click New Sell Order again and it Fills.

    This is an early stage development so some buttons/tabs are empty.
    Thank you,
    Regards,
    Peter
    Attached Files Attached Files

  8. #8
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    See attached where the two userforms' proper initialize events have been used.
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  9. #9
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location
    Thank you yet again, it looks as if I was over complicating a simple show command.
    Regards,
    Peter.

Posting Permissions

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