Reputation: 11
I'm developing an application using MS Access and VBA. Unfortunately i have this problem:
I set the recordset of a listBox using VBA and a query
'In the select, i select 4 fields
SQL = "..."
rs.CursorLocation = adUseClient
rs.Open SQL, Conn, adOpenKeyset, adLockOptimistic
If Not rs.EOF Then
Set Me.MyList.Recordset = rs
Me.MyList.SetFocus
Else
Set Me.MyList.Recordset = Nothing
Me.MyList.SetFocus
End If
rs.Close
The problem is that when i execute this piece of code it works but only if i set the number of the columns of my listBox at 1 or 2. I need to show 4 column, so, this for me is a problem.
I also have tried to decompile the application, but nothing has changed.
Can anyone tells me how to resolve it? Thank you very much for your help
Upvotes: 0
Views: 1000
Reputation: 8518
You need to set the Column Count
on the properties window to 4 and also define the column widths in the form of 0cm;1.217cm;2.064cm;3.545cm
.
You can do this at design mode or by code:
Dim sql_ As String
sql_ = "Your SQL command..."
With Me.MyList
.ColumnCount = 4
.ColumnWidths = "0cm;1.217cm;2.064cm;3.545cm"
.RowSourceType = "Table/Query"
.RowSource = sql_
End With
Upvotes: 1