Help Needed - Converting Listbox Code from VB6 to Access 97

  • Thread starter Thread starter Jado
  • Start date Start date
J

Jado

Hi

i'm trying to get some code to work in Access 97 that was writen for VB6.

I have found that the Listbox Methods and Properties in Access are quite
different to those in VB6.

i was wondering if anyone knows how to achive the equivilent results.

here's the VB6 code, lstFoundwords = myListBox

------------

Do While FuzzyStringSearch.FindNext(lngFindStart, lngFindLength, 1)
lstFoundwords.AddItem Mid$(txtSearchText, lngFindStart, lngFindLength)
lstFoundwords.ItemData(lstFoundwords.NewIndex) = MakeLong(lngFindStart,
lngFindLength)
Loop

------------

i think i can replace 'lstFoundwordsAddItem' with:

Me.lstFoundwords.RowSource = Me.lstFoundwords.RowSource & stuff

but i'm not sure how to handle:

lstFoundwords.ItemData( lstFoundwords.NewIndex)

If anyone has an idea, or of a good resource I'd appreciate it.


Thanks
Jado
 
i think i can replace 'lstFoundwordsAddItem' with:

Me.lstFoundwords.RowSource = Me.lstFoundwords.RowSource & stuff

but i'm not sure how to handle:

lstFoundwords.ItemData( lstFoundwords.NewIndex)

Using a ValueList in an Access list box is simple: probably too simple. You
can use Instr(..., ";", ...) to shell out the individual bits -- actually
the Split() function would work too. You would have to do counting and
sorting on your own though, and then rebuild the RowSource string. It's not
too hard, but it is a bit fiddly.

Hope that helps


Tim F
 
Hi,
I think your best bet would be to insert the values into a table each time (deleting previous values first).
So first you would create a table with two fields (yourLongField,yourTextField)

So something like:

Dim strSql as String
CurrentDb.Execute "Delete * From yourTable"
Do While FuzzyStringSearch.FindNext(lngFindStart, lngFindLength, 1)
strSql = "Insert Into yourTable (yourLongField,yourTextField) Values(" & _
MakeLong(lngFindStart,lngFindLength) & ",""" & _
Mid$(txtSearchText, lngFindStart, lngFindLength) & """)"
CurrentDb.Execute strSql
Loop

lstFoundWords.RowSource = "Select * From yourTable"
lstFoundWords.Requery

Just make sure that the ColumnCount of the listbox is set to 2 and the BoundColumn is 1.
I assume you already have the MakeLong function.

HTH
Dan Artuso, MVP
 
Hi

Thanks for the response and sorry for the slow reply!

I shall try this workarround and let you know if i run into any problems.

Thanks again

Jado

Dan Artuso said:
Hi,
I think your best bet would be to insert the values into a table each time
(deleting previous values first).
 
Back
Top