Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default ListBox / UserForm interaction

Never mind.

Seeing "vbModal" below got me thinking. Both UserForm1 and UserForm2 had
ShowModal set to True. I changed them both to False and everything worked
like I wanted.

Sorry to have taken up your time. I should have thought of this in the
beginning.

"Chip Pearson" wrote:

It would be helpful if you posted the relevant code so that one could
try to recreate your situation. Based on your description, I created
Userform1 with a ListBox containing 10 items. The click event is this:

Private Sub ListBox1_Click()
UserForm2.Show vbModal
End Sub

This shows UserForm2 modally. Userform2 has a Cancel button attached
to the code

Private Sub btnCancel_Click()
Unload Me
End Sub

When I display Userform1 and click in ListBox1, Userform2 displays
until closed. Userform1 remains open with the same item still
selected in the ListBox. Userform2 does not reappear until another
click on ListBox1 on UserForm1.

I suspect that if you posted the relevant code (enough to faithfully
recreate the problem, but no more than that), someone will find out
what is really going on.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com





On Wed, 24 Mar 2010 14:10:01 -0700, Luke
wrote:

I have a UserForm1 with a ListBox1 in it. When I click on an entry from
ListBox1, UserForm2 appears. UserForm2 has the equivalent of "OK" and
"Cancel" buttons on it (among other things).

I had been so busy testing other features that it never occurred to me to
test the Cancel button until now. What I found is that, when Cancel is
clicked, UserForm2 unloads (as it should) and then immediately reappears.
The "UserForm2.Show" line of code is the first line in the ListBox1_Click()
sub. I assumed that, since an entry was still selected in ListBox1, it was
counting that as a click and re-running the ListBox1_Click() sub.

To fix this, I added this line of code to the CommandButton2_Click() sub
(the Cancel button): UserForm1.ListBox1.ListIndex = 0. That line of code
came after the "Unload UserForm2" line in the same sub. However, I then got
a Run-time error 400: Form already displayed; can't show modally. The
highlighted line of code was the UserForm2.Show line in the ListBox1_Click()
sub.

How can I click the Cancel button on UserForm2, unload UserForm2, and have
ListBox1 (in UserForm1) sitting there ready for me to choose a new entry?

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
fill userform textbox from userform listbox clik event GregJG[_21_] Excel Programming 3 December 7th 08 04:47 PM
userform listbox cannot get listbox.value to transfer back to main sub [email protected] Excel Programming 1 May 17th 06 09:44 PM
Userform interaction with the VBA code [email protected] Excel Programming 0 March 11th 05 03:45 PM
Flow of control in VBA Question - Userform Interaction Alan Excel Programming 3 December 23rd 04 01:12 PM
UserForm Interaction Bob Phillips[_5_] Excel Programming 0 September 22nd 03 08:12 PM


All times are GMT +1. The time now is 04:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"