0

I have a sub in VBA where I am fetching data from database on button click event like below

Public Sub getNearestPfk(runNR As Integer)
Dim DB As dao.Database
Dim rs As dao.Recordset
Dim sqlString As String
Dim record As Object
Dim objPFK As Pfk

Dim i As Integer

i = 0


Set DB = CurrentDb
sqlString = " SELECT TOP 5 T_TEMP_DESTANCE_CAL.* FROM T_TEMP_DESTANCE_CAL WHERE RUNID = " & runNR & " ORDER by DISTANCE "
MsgBox (sqlStringGetNearestPFK)

Set rs = DB.OpenRecordset(sqlString)

Do Until rs.EOF

objPFK.ID = rs!ID
objPFK.fistName = rs!firstName
objPFK.lastName = rs!lastName
objPFK.distance = rs!distance
objPFK.duration = rs!duration
objPFK.address = rs!address

arrayObjPFK(i) = objPFK


rs.MoveNext
i = i + 1
Loop


rs.Close
Set rs = Nothing
Set DB = Nothing


End Sub

Now I have all the data Which I want to display

how should I display this data in listbox so on this button click a listbox will populate

1

1 Answer 1

1

You can set the list box property called Row Source Type to Table/Query and then your Row Source property to the SQL statement.

If you want to update the list box, simply update the Row Source.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.