Listbox for counting number of records in table

P

Peter Adema

I have created a hidden listbox("kantoren") on a Form.
This listbox is linked to a table. I want to use the number of records in
VBA to determain a loop.
The problem is that the listbox is not refreshed when I delete or add
records in the table.

See here a part of the code:

Set ListControl = Forms!hoofdmenu!kantoren
With ListControl
TELLER = .ListCount
End With

For TEL = 1 To TELLER

Does anyone have a solution?
 
A

Andi Mayer

I have created a hidden listbox("kantoren") on a Form.
This listbox is linked to a table. I want to use the number of records in
VBA to determain a loop.
The problem is that the listbox is not refreshed when I delete or add
records in the table.

See here a part of the code:

Set ListControl = Forms!hoofdmenu!kantoren
With ListControl
TELLER = .ListCount
End With

For TEL = 1 To TELLER

Does anyone have a solution?

requery the listControl
 
D

Dirk Goldgar

Peter Adema said:
I have created a hidden listbox("kantoren") on a Form.
This listbox is linked to a table. I want to use the number of
records in VBA to determain a loop.
The problem is that the listbox is not refreshed when I delete or add
records in the table.

See here a part of the code:

Set ListControl = Forms!hoofdmenu!kantoren
With ListControl
TELLER = .ListCount
End With

For TEL = 1 To TELLER

Does anyone have a solution?

As others have said, you'd have to call the list box's Requery method to
update the ListCount property to reflect changes to the table. But I'm
curious as to the purpose of a hidden list box. If all you want to know
is the number of records in the table, why not just call the DCount()
function:

TELLER = DCount("*", "YourTableNameHere")

?
 
D

David C. Holley

What's the big picture here? What information are you putting into the
listbox? How are you using the information? Fundamentally, if its a
count of the records in a particular table that you need, DCOUNT() will
accomplish pretty much the same thing.
 
Top