Form works once only

G

Gleam

This routine works once, but fails on subsequent occassions.
Private Sub wholemonthbutton3_click()
ListBox1.ListIndex=0
ListBox2.ListIndex = ListBox2.ListCount - 1 ' This line fails
Msgbox "Listbox2.Value = " & ListBox2.Value _
& " Count =" & ListBox2.ListCount
end sub

The first time the sub works. The second time ListBox2.value =""
When the OK button is hit I have Unload Me.
When the routine has returned to the calling program I have Unload
DatesForGraph. Before the routine is called again I have the same statement.
So I think it should be unloaded 3 times but still it gives me the wrong
answer! Please advise where am I may be going wrong. (Excel 2003)
 
P

Patrick Molloy

is there any data in listbox2 ?

you aren't clear on why you get the wrong answer, and if the form is
unloaded, does the forms load event correctly populaet whatever listboxes you
have?
Remember that if you unload a form, then any changes that were made are lost
unless saved somewhere else and re-loaded. Use HIDE to preserve values.
 
G

Gleam

Listbox2 displays the correct data every time.
I have several forms in the file and wonder if I have another ListBox2 in a
different form and Excel is getting confused.

I am thinking of trying this when I get a chance:
DatesForGraph.ListBox2.ListIndex = DatesForGraph.ListBox2.ListCount - 1
Listbox2.Value = DatesForGraph.Listbox2.Value
where form name=DatesForGraph
 

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