Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Me Reference (XP;SP3)

    What does "Me" represent in the following line of code?

    Dim LbList As Variant

    LbList = Me.ListBox1.List 'Store the list in an array for sorting


    If I try to run the code I receive a compile error: Invalid use of Me keyword

    Thanks,
    John

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Me Reference (XP;SP3)

    It depends on where the code is.

    Me could refer to the sheet object or the userform depending on where the code is.

    Where is the code located?

    Steve

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    What it represents depends on where the code is. If it is in code that is in a module behind a UserForm, then it represents the UserForm. If it is code that is in a module behind a worksheet, then it represents the worksheet. If it is code that is in the module behind the workbook object, then it represents the workbook. If it is in code that is in a normal module, it represents nothing, and you get that error.
    Legare Coleman

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    That code does not have a "Me." in it. That code looks like it is looking for a listbox named ListBox2 on a form named Receipts. The two lines of code below seem to work fine for me when they are in a module behind a UserForm named Receipts,

    <code>
    LbList = Receipts.ListBox2.List
    LbList = Me.ListBox2.List
    </code>

    What happens for you?
    Legare Coleman

  5. #5
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    Legare,

    I had it in a module and then moved it behind a FORM

    I am trying to sort the contents of a listbox:

    Sub UserForm_Activate()
    Dim i As Long
    Dim j As Long
    Dim sTemp As String
    Dim sTemp2 As String
    Dim LbList As Variant

    'Store the list in an array for sorting
    LbList = Me.ListBox2.List

    'Bubble sort the array on the first value
    For i = LBound(LbList, 1) To UBound(LbList, 1) - 1
    For j = i + 1 To UBound(LbList, 1)
    If LbList(i, 0) > LbList(j, 0) Then
    'Swap the first value
    sTemp = LbList(i, 0)
    LbList(i, 0) = LbList(j, 0)
    LbList(j, 0) = sTemp
    'Swap the second value
    sTemp2 = LbList(i, 1)
    LbList(i, 1) = LbList(j, 1)
    LbList(j, 1) = sTemp2
    End If
    Next j
    Next i
    End Sub

    'Remove the contents of the listbox
    Me.ListBox2.Clear

    'Repopulate with the sorted list
    Me.ListBox2.List = LbList



    Regards,
    John

  6. #6
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    Legare,

    I modified (bold text) my last post. I see what your are saying. When I now run it I receive an "unspecified error message" on line:

    'Remove the contents of the listbox
    Me.ListBox2.Clear


    Regards,
    John

  7. #7
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    Is the listbox bound to a range of cells? If so, you can not use the Clear method, or Assign items to the listbox. If you do, that is the error you will get. If this is a bound listbox, you will have to sort the items in the bound range.
    Legare Coleman

  8. #8
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    Legare,

    The listbox is bound to a range ie RowSource. Guess I'll have to copy the RowSource somewhere else, sort it and then reset the RowSource.

    Thanks,
    John

  9. #9
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    You can also remove the RowSource and then use the form initilize event to load the items into the listbox in any order you want them.
    Legare Coleman

  10. #10
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Me Reference (XP;SP3)

    Great suggestion.

    Thanks,
    John

Posting Permissions

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