ListCount being weird

A

Alex

I have a listbox, whose rowsource I set during the forms On Current event.

The problem is when I open the form, on acFormAdd, the listcount property of
the listbox shows up as 1. This is of course false, since the listbox is
empty. Does anyone know why this is happening?

Thanks!

Alex Brown
 
J

John W. Vinson

I have a listbox, whose rowsource I set during the forms On Current event.

The problem is when I open the form, on acFormAdd, the listcount property of
the listbox shows up as 1. This is of course false, since the listbox is
empty. Does anyone know why this is happening?

Since you didn't post your code, it's a pure guess - but if your rowsource
query is updateable, it's showing the blank New Record as the "1".

Make it a snapshot query to make it non-updateable (you won't be updating the
Rowsource query in this case).
 
D

Dirk Goldgar

Alex said:
I have a listbox, whose rowsource I set during the forms On Current event.

The problem is when I open the form, on acFormAdd, the listcount property
of
the listbox shows up as 1. This is of course false, since the listbox is
empty. Does anyone know why this is happening?

Thanks!

Alex Brown


Does your list box have its Column Heads property set to Yes/True? If so,
the row of column headers will count toward the ListCount.
 
A

Alex

This is my code, for the forms OnCurrent event.

Me.lst_Informes.RowSource = "SELECT IdInforme, FechaInforme, IdObra FROM
Cat_Informes WHERE IdObra = " & Me.IDObra & _
" ORDER BY FechaInforme;"
Me.lst_Informes.ColumnHeads = False
Me.lst_Informes.ColumnCount = 3
Me.lst_Informes.ColumnWidths = "0 cm; 4 cm; 0 cm"

I have and add button, that will open up another form, for which I enter
data, when I finish filling out that form, save and close it. That forms
date will appear on the listbox. When I double click on the date it opens it
up again. However, when the listbox is empty, it jumps to another form
first, then back to the regular form. The problem is since listcount is
showing up as 1, the code believes the listbox has an item, and it skips the
intermediate form.

How do I make this a snapshot query?

Thanks for your help.

Alex Brown
 
A

Alex

No, the column heads are specifically set to false. (Although this is
default). In John's reply I put in my code. Thanks!

Alex Brown
 
J

John W. Vinson

This is my code, for the forms OnCurrent event.

Me.lst_Informes.RowSource = "SELECT IdInforme, FechaInforme, IdObra FROM
Cat_Informes WHERE IdObra = " & Me.IDObra & _
" ORDER BY FechaInforme;"
Me.lst_Informes.ColumnHeads = False
Me.lst_Informes.ColumnCount = 3
Me.lst_Informes.ColumnWidths = "0 cm; 4 cm; 0 cm"

I have and add button, that will open up another form, for which I enter
data, when I finish filling out that form, save and close it. That forms
date will appear on the listbox. When I double click on the date it opens it
up again. However, when the listbox is empty, it jumps to another form
first, then back to the regular form. The problem is since listcount is
showing up as 1, the code believes the listbox has an item, and it skips the
intermediate form.

How do I make this a snapshot query?

A simpler way would be to just change the RowSource from

SELECT IdInforme ...

to

SELECT DISTINCT IdInforme ...

This will make the query non-updateable and get rid of the blank new record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top