PDA

Click to See Complete Forum and Search --> : Listbox Problem


MethadoneBoy
Jul 14th, 2005, 04:38 AM
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 -

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

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

Private Sub Cmd553_Click()

Dim DB As Database
Dim RS As Recordset
Dim strAcc As String
Set DB = CurrentDb()
strAcc = "SELECT NBR_FUND FROM Label_Root WHERE NBR_COMP IN(553);"
Set RS = DB.OpenRecordset(strAcc)

If Not RS.EOF Then RS.MoveFirst
Do While Not RS.EOF
'txtRes.SetFocus
'txtRes.Text = txtRes.Text & " : " & RS!NBR_FUND
lstRecords.SetFocus
lstRecords.AddItem RS!NBR_FUND
lstRecords.ItemData(lstRecords.NewIndex) = RS!NBR_FUND
RS.MoveNext
Loop

MsgBox "Active"

End Sub


Many thanks

GIS_Mike
Jul 14th, 2005, 06:55 AM
Maybe the AddItem method only accepts a string type as the input.

MethadoneBoy
Jul 14th, 2005, 07:56 AM
'Fraid not. It returns the same error message even if I use a String.