Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating list box dynamically 1

Status
Not open for further replies.

mwitcomb

IS-IT--Management
Jul 19, 2004
1
GB
I`m trying to populate a list box dynamically depending on an SQL query when different conditions are met. I can do this easily when using access2002 with the .AddItem command, however when using access97 this command does not appear and so the code does not work.

Suggestions on getting round this problem?

The list box is populated with a set of data from one column eg below:

Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL, dbOpenSnapshot)

If rst.EOF And getuserRole = 3 Then
MsgBox "You have no changes to impact", vbInformation
Cancel = True
Else

With rst
.MoveFirst
Do While True
lstImpacts.AddItem = rst("catnumber")
rst.MoveNext
Loop
.Close
End With

End If
Set rst = Nothing

How do I get the above to work in 97?
 
The .AddItem and .RemoveItem method of native Access list and comboboxes became available in 2002. For previous versions, concatinate the rowsource:

[tt]dim strRowSource as String
...
strRowSource = strRowSource & rst("catnumber") & ";"
...
Me!lstImpacts.RowSource = strRowSource[/tt]

Welcome to Tek-Tips!

To get the most out of the membership, take a look at faq181-2886. One of the things addressed there, is finding the right forum. This is Visual Basic Databases forum. For future Access questions, try out some of the Access fora (see the the Related Forums box at right)

Good Luck!

Roy-Vidar
 
i typically use the following syntax...

lstImpacts.AddItem = rst!catnumber

i don't know if this is correct, but it usually works for me.

DarkMain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top