Results 1 to 3 of 3

Thread: Listbox Problem

  1. #1

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Listbox Problem

    Hi guys,

    I'm a beginner when it comes to VBA and I'm encountering a rather annoying error with a listbox on a form that I'm writing.

    My form has a button that is called Cmd553. It also contains a listbox called lstRecords. The problem arises when I try to add items from a database to the listbox. Upon clicking the 553 button, an error appears saying

    Compile Error: Method or data member not found
    Also, this line of code is highlighted -

    VB Code:
    1. lstRecords -this part highlighted: .AddItem -end highlighting RS!NBR_FUND

    I'd appreciate any help you can give. Here's the problematic code

    VB Code:
    1. Private Sub Cmd553_Click()
    2.    
    3.     Dim DB As Database
    4.     Dim RS As Recordset
    5.     Dim strAcc As String
    6.     Set DB = CurrentDb()
    7.     strAcc = "SELECT NBR_FUND FROM Label_Root WHERE NBR_COMP IN(553);"
    8.     Set RS = DB.OpenRecordset(strAcc)
    9.    
    10.     If Not RS.EOF Then RS.MoveFirst
    11.     Do While Not RS.EOF
    12.         'txtRes.SetFocus
    13.         'txtRes.Text = txtRes.Text & " : " & RS!NBR_FUND
    14.         lstRecords.SetFocus
    15.         lstRecords.AddItem RS!NBR_FUND
    16.         lstRecords.ItemData(lstRecords.NewIndex) = RS!NBR_FUND
    17.         RS.MoveNext
    18.     Loop
    19.    
    20.     MsgBox "Active"
    21.    
    22. End Sub

    Many thanks
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

  2. #2
    Junior Member
    Join Date
    Jul 2005
    Posts
    20

    Re: Listbox Problem

    Maybe the AddItem method only accepts a string type as the input.

  3. #3

    Thread Starter
    Addicted Member MethadoneBoy's Avatar
    Join Date
    Oct 2001
    Location
    Preferably somewhere between Keira Knightley and Diane Kruger but I'm not fussy
    Posts
    180

    Re: Listbox Problem

    'Fraid not. It returns the same error message even if I use a String.
    "'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."

Posting Permissions

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



Click Here to Expand Forum to Full Width