[2003] Listbox control displays list only after clicking-on, then clicking away.

  • Thread starter JohnM77 via AccessMonster.com
  • Start date
J

JohnM77 via AccessMonster.com

I have an unbound Listbox control that I'm populating using the additem
method. After populating the Listbox, it appears empty until the user clicks
on it and then clicks away (Listbox loses focus). In the immediate window, I
can verify that the items are present using ?Listbox.ListCount, but the items
are never displayed until the little clicking exercise is performed. I tried
programmatically altering the focus after filling the Listbox, but that
didn't solve the problem.

Anyone seen this before? It seems like a bug, but perhaps I'm doing something
to cause it. Any suggestions are appreciated.

Thanks,
John
 
K

Klatuu

Can't switch to 2003 at the moment to test there, but I did test in 2007 and
did not get what you are getting. But, you might try requerying the list box
after you add the item.

Me.MyList.AddItem "Foobar"
Me.MyList.Requery
 
J

JohnM77 via AccessMonster.com

Thanks for the suggestion. I tried the requery, and it had no effect. I just
noticed also that the listbox items disappear when I minimize the form and
then maximize again. The items are still there; they just aren't visible. I
tried messing with foreground/background colors, too, thinking that maybe it
was a white-on-white issue. No luck! This is very strange.
Can't switch to 2003 at the moment to test there, but I did test in 2007 and
did not get what you are getting. But, you might try requerying the list box
after you add the item.

Me.MyList.AddItem "Foobar"
Me.MyList.Requery
I have an unbound Listbox control that I'm populating using the additem
method. After populating the Listbox, it appears empty until the user clicks
[quoted text clipped - 9 lines]
Thanks,
John
 
K

Klatuu

Post the code where you are populating the list box, please.
--
Dave Hargis, Microsoft Access MVP


JohnM77 via AccessMonster.com said:
Thanks for the suggestion. I tried the requery, and it had no effect. I just
noticed also that the listbox items disappear when I minimize the form and
then maximize again. The items are still there; they just aren't visible. I
tried messing with foreground/background colors, too, thinking that maybe it
was a white-on-white issue. No luck! This is very strange.
Can't switch to 2003 at the moment to test there, but I did test in 2007 and
did not get what you are getting. But, you might try requerying the list box
after you add the item.

Me.MyList.AddItem "Foobar"
Me.MyList.Requery
I have an unbound Listbox control that I'm populating using the additem
method. After populating the Listbox, it appears empty until the user clicks
[quoted text clipped - 9 lines]
Thanks,
John
 
J

JohnM77 via AccessMonster.com

This code is in a subform, which is imbedded on a parent form. I'm using an
ADO recordset to gather items for the listbox.

Public Sub Form_Current()
Dim rsRec As New ADODB.Recordset
Dim conDB As ADODB.Connection

On Error GoTo xErr

Set conDB = CurrentProject.Connection
rsRec.Open "SELECT * FROM Drawings_InquiriesWhereUsedQuery WHERE
ProductTypeID = " & Me.ProductTypeID & " AND DrawingSizeID = " & Me.
DrawingSizeID & " AND DrawingNumber = " & Me.DrawingNumber & " ORDER BY
Inquiry ASC", conDB, adOpenStatic, adLockOptimistic

Do Until rsRec.EOF
Form_frmDrawings_Main.lstInquiries.AddItem rsRec!InquiryYear & ";" &
rsRec!InquiryNumber & ";" & rsRec!Inquiry
rsRec.MoveNext
Loop
rsRec.Close
conDB.Close

xErr:
If Err.Number <> 0 Then
MsgBox "Error #" & Err.Number & ": " & Err.Description
End If
Set rsRec = Nothing
Set conDB = Nothing
End Sub
Post the code where you are populating the list box, please.
Thanks for the suggestion. I tried the requery, and it had no effect. I just
noticed also that the listbox items disappear when I minimize the form and
[quoted text clipped - 13 lines]
 
K

Klatuu

I don't see anything that I think may cause the problem, but I am curious as
to why you are using recordset processing to populate the list box. I took a
moment to test an idea, and it works well.
First, use your query as the Row Source of the List box including the
references to the form controls. Then in the form current event all you have
to do is requery the list box control.

So this would be something like the row source of the list box in design view:

"SELECT * FROM Drawings_InquiriesWhereUsedQuery WHERE
ProductTypeID = " & Me.ProductTypeID & " AND DrawingSizeID = " & Me.
DrawingSizeID & " AND DrawingNumber = " & Me.DrawingNumber & " ORDER BY
Inquiry ASC"

Then in the Current Event:

Me.MyListBox.Requery

Simpler and much faster.
--
Dave Hargis, Microsoft Access MVP


JohnM77 via AccessMonster.com said:
This code is in a subform, which is imbedded on a parent form. I'm using an
ADO recordset to gather items for the listbox.

Public Sub Form_Current()
Dim rsRec As New ADODB.Recordset
Dim conDB As ADODB.Connection

On Error GoTo xErr

Set conDB = CurrentProject.Connection
rsRec.Open "SELECT * FROM Drawings_InquiriesWhereUsedQuery WHERE
ProductTypeID = " & Me.ProductTypeID & " AND DrawingSizeID = " & Me.
DrawingSizeID & " AND DrawingNumber = " & Me.DrawingNumber & " ORDER BY
Inquiry ASC", conDB, adOpenStatic, adLockOptimistic

Do Until rsRec.EOF
Form_frmDrawings_Main.lstInquiries.AddItem rsRec!InquiryYear & ";" &
rsRec!InquiryNumber & ";" & rsRec!Inquiry
rsRec.MoveNext
Loop
rsRec.Close
conDB.Close

xErr:
If Err.Number <> 0 Then
MsgBox "Error #" & Err.Number & ": " & Err.Description
End If
Set rsRec = Nothing
Set conDB = Nothing
End Sub
Post the code where you are populating the list box, please.
Thanks for the suggestion. I tried the requery, and it had no effect. I just
noticed also that the listbox items disappear when I minimize the form and
[quoted text clipped - 13 lines]
Thanks,
John
 
L

Linq Adams via AccessMonster.com

My guess, since we're talking about v2003, is that this is a variation of the
SP3 service pack bug that we usually associate with comboboxes. This problem
is one of the most commonly reported bugs associated with this service pack.
If you have SP3 installed but haven't installed the hotfix, here's a page by
Allen Browne with most of the bugs and a link to Microsoft's site where
there's a hotfix:

http://allenbrowne.com/bug-Access2003SP3.html
 
J

JohnM77 via AccessMonster.com

Dave:
I'm using all unbound controls to allow me to perform in-depth validation of
the user's input data. In this case, the user can add-to/delete-from the
Listbox, perform other edits, then click 'Save', and only then will data be
stored in tables.

Linq:
I installed the hotfix, but it didn't solve the problem. I tried substituting
a combobox for the listbox control, and the combobox works fine. I would use
that as a permanent solution, but I need to display multiple values at a time
in the list. I've scoured google for hints to this issue, but I'm striking
out. Seems like it should be more common, as I don't think I'm doing anything
on the fringe. Thanks for your suggestions, nevertheless!

Best regards,
John
 

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