Abbos Ergashev
Abbos Ergashev

Reputation: 1

Queries in Microsoft Access

I have queries, tables, and forms in Microsoft Access. I have a list box and a button in one of my forms. When I click the button, the data in the list box should appear. But it doesn't.

form: form table: table

button OnClick code:

Private Sub btn_Click()
Me.listt.RowSource = "SELECT * FROM shartnomachilar"
End Sub

I should see the data in the table when I click the button, but it doesn't

Upvotes: -1

Views: 66

Answers (1)

Harun24hr
Harun24hr

Reputation: 37050

Try the following codes.

Private Sub btn_Click()
    Me.listt.ColumnCount = CurrentDb.TableDefs("shartnomachilar").Fields.Count
    Me.listt.RowSource = "SELECT * FROM shartnomachilar"
End Sub

CurrentDb.TableDefs("shartnomachilar").Fields.Count this line will count fields (means, columns) in the table and will display those columns in listbox control.

Listbox control has default property Row Source Type as Table/Query. If it is not then set this property as Table/Query.

enter image description here

Upvotes: 0

Related Questions