PC Review


Reply
Thread Tools Rate Thread

Command button - won't execute twice in sequence

 
 
L Mehl
Guest
Posts: n/a
 
      12th Oct 2004
Hello --

I have 3 command buttons (btnA, btnB, btnC) on a worksheet, each performing
the same task on 3 different columns:
- Click button
- show UserForm (contains only a listbox)
- click listbox item
- selected item is assigned to a cell below the button; form closes

Each button works fine if btnB is clicked, for example, after btnA.

Problem: btnA will not show the UserForm if clicked immediately after
clicking btnA the first time.
The user might have made a mistake and wants to select a different item from
the listbox; I don't want him/her to have to click another button just to
make the desired one "active" again.

Code for listbox Click event is:

Private Sub lstSelectComponent_Click()
'clicking a model in listbox selects the model ID
Dim strCellEqpSelName As String 'range name of cell holding selected
eqp name
strCellEqpSelName = "sel_" & g_strCellEqpSel
Cells.Range(strCellEqpSelName).Value = Me.lstSelectComponent.Value
frmSelectComponent.Hide
Exit Sub
End Sub

Can someone tell me what is wrong with my approach? Is there some code
needed to "re-activate" the clicked button?

Thanks for any help.

Larry Mehl




 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      12th Oct 2004
Not really sure about what your problem is, but how about having a command
button on the userform that the user clicks when they are happy they have
made the correct selection from the listbox.

--

HTH

RP

"L Mehl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello --
>
> I have 3 command buttons (btnA, btnB, btnC) on a worksheet, each

performing
> the same task on 3 different columns:
> - Click button
> - show UserForm (contains only a listbox)
> - click listbox item
> - selected item is assigned to a cell below the button; form closes
>
> Each button works fine if btnB is clicked, for example, after btnA.
>
> Problem: btnA will not show the UserForm if clicked immediately after
> clicking btnA the first time.
> The user might have made a mistake and wants to select a different item

from
> the listbox; I don't want him/her to have to click another button just to
> make the desired one "active" again.
>
> Code for listbox Click event is:
>
> Private Sub lstSelectComponent_Click()
> 'clicking a model in listbox selects the model ID
> Dim strCellEqpSelName As String 'range name of cell holding selected
> eqp name
> strCellEqpSelName = "sel_" & g_strCellEqpSel
> Cells.Range(strCellEqpSelName).Value = Me.lstSelectComponent.Value
> frmSelectComponent.Hide
> Exit Sub
> End Sub
>
> Can someone tell me what is wrong with my approach? Is there some code
> needed to "re-activate" the clicked button?
>
> Thanks for any help.
>
> Larry Mehl
>
>
>
>



 
Reply With Quote
 
L Mehl
Guest
Posts: n/a
 
      13th Oct 2004
Bob --

Thanks for responding. That would work, but it would add a step for the
user (for each "real" button clicked).

Is it possible to hide your suggested button and write code to "click" that
button every time a "real" button is clicked?

Larry

"Bob Phillips" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> Not really sure about what your problem is, but how about having a command
> button on the userform that the user clicks when they are happy they have
> made the correct selection from the listbox.
>
> --
>
> HTH
>
> RP
>
> "L Mehl" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello --
> >
> > I have 3 command buttons (btnA, btnB, btnC) on a worksheet, each

> performing
> > the same task on 3 different columns:
> > - Click button
> > - show UserForm (contains only a listbox)
> > - click listbox item
> > - selected item is assigned to a cell below the button; form closes
> >
> > Each button works fine if btnB is clicked, for example, after btnA.
> >
> > Problem: btnA will not show the UserForm if clicked immediately after
> > clicking btnA the first time.
> > The user might have made a mistake and wants to select a different item

> from
> > the listbox; I don't want him/her to have to click another button just

to
> > make the desired one "active" again.
> >
> > Code for listbox Click event is:
> >
> > Private Sub lstSelectComponent_Click()
> > 'clicking a model in listbox selects the model ID
> > Dim strCellEqpSelName As String 'range name of cell holding

selected
> > eqp name
> > strCellEqpSelName = "sel_" & g_strCellEqpSel
> > Cells.Range(strCellEqpSelName).Value = Me.lstSelectComponent.Value
> > frmSelectComponent.Hide
> > Exit Sub
> > End Sub
> >
> > Can someone tell me what is wrong with my approach? Is there some code
> > needed to "re-activate" the clicked button?
> >
> > Thanks for any help.
> >
> > Larry Mehl
> >
> >
> >
> >

>
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      13th Oct 2004
Larry,

You could, but that would defeat the object of the button and you would be
in the same position that you are in now, mistakes require starting again.

--

HTH

RP

"L Mehl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Bob --
>
> Thanks for responding. That would work, but it would add a step for the
> user (for each "real" button clicked).
>
> Is it possible to hide your suggested button and write code to "click"

that
> button every time a "real" button is clicked?
>
> Larry
>
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
> > Not really sure about what your problem is, but how about having a

command
> > button on the userform that the user clicks when they are happy they

have
> > made the correct selection from the listbox.
> >
> > --
> >
> > HTH
> >
> > RP
> >
> > "L Mehl" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hello --
> > >
> > > I have 3 command buttons (btnA, btnB, btnC) on a worksheet, each

> > performing
> > > the same task on 3 different columns:
> > > - Click button
> > > - show UserForm (contains only a listbox)
> > > - click listbox item
> > > - selected item is assigned to a cell below the button; form closes
> > >
> > > Each button works fine if btnB is clicked, for example, after btnA.
> > >
> > > Problem: btnA will not show the UserForm if clicked immediately after
> > > clicking btnA the first time.
> > > The user might have made a mistake and wants to select a different

item
> > from
> > > the listbox; I don't want him/her to have to click another button just

> to
> > > make the desired one "active" again.
> > >
> > > Code for listbox Click event is:
> > >
> > > Private Sub lstSelectComponent_Click()
> > > 'clicking a model in listbox selects the model ID
> > > Dim strCellEqpSelName As String 'range name of cell holding

> selected
> > > eqp name
> > > strCellEqpSelName = "sel_" & g_strCellEqpSel
> > > Cells.Range(strCellEqpSelName).Value = Me.lstSelectComponent.Value
> > > frmSelectComponent.Hide
> > > Exit Sub
> > > End Sub
> > >
> > > Can someone tell me what is wrong with my approach? Is there some

code
> > > needed to "re-activate" the clicked button?
> > >
> > > Thanks for any help.
> > >
> > > Larry Mehl
> > >
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
L Mehl
Guest
Posts: n/a
 
      15th Oct 2004
Bob --

What is the mistake to which you refer?

Which button would be "defeated"? I wouldn't mind a workaround that
"cleared" the clicked button and made it ready for being clicked again in
sequence.

Larry

"Bob Phillips" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Larry,
>
> You could, but that would defeat the object of the button and you would be
> in the same position that you are in now, mistakes require starting again.
>
> --
>
> HTH
>
> RP
>
> "L Mehl" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Bob --
> >
> > Thanks for responding. That would work, but it would add a step for the
> > user (for each "real" button clicked).
> >
> > Is it possible to hide your suggested button and write code to "click"

> that
> > button every time a "real" button is clicked?
> >
> > Larry
> >
> > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > news:#(E-Mail Removed)...
> > > Not really sure about what your problem is, but how about having a

> command
> > > button on the userform that the user clicks when they are happy they

> have
> > > made the correct selection from the listbox.
> > >
> > > --
> > >
> > > HTH
> > >
> > > RP
> > >
> > > "L Mehl" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Hello --
> > > >
> > > > I have 3 command buttons (btnA, btnB, btnC) on a worksheet, each
> > > performing
> > > > the same task on 3 different columns:
> > > > - Click button
> > > > - show UserForm (contains only a listbox)
> > > > - click listbox item
> > > > - selected item is assigned to a cell below the button; form closes
> > > >
> > > > Each button works fine if btnB is clicked, for example, after btnA.
> > > >
> > > > Problem: btnA will not show the UserForm if clicked immediately

after
> > > > clicking btnA the first time.
> > > > The user might have made a mistake and wants to select a different

> item
> > > from
> > > > the listbox; I don't want him/her to have to click another button

just
> > to
> > > > make the desired one "active" again.
> > > >
> > > > Code for listbox Click event is:
> > > >
> > > > Private Sub lstSelectComponent_Click()
> > > > 'clicking a model in listbox selects the model ID
> > > > Dim strCellEqpSelName As String 'range name of cell holding

> > selected
> > > > eqp name
> > > > strCellEqpSelName = "sel_" & g_strCellEqpSel
> > > > Cells.Range(strCellEqpSelName).Value =

Me.lstSelectComponent.Value
> > > > frmSelectComponent.Hide
> > > > Exit Sub
> > > > End Sub
> > > >
> > > > Can someone tell me what is wrong with my approach? Is there some

> code
> > > > needed to "re-activate" the clicked button?
> > > >
> > > > Thanks for any help.
> > > >
> > > > Larry Mehl
> > > >
> > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Vic Eldridge
Guest
Posts: n/a
 
      15th Oct 2004
Hi Larry,

I have a hunch there's some other code in your Userform's Initialise event
that makes a difference.

Try replacing
frmSelectComponent.Hide
with
Unload frmSelectComponent


Regards,
Vic Eldridge


"L Mehl" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Bob --
>
> What is the mistake to which you refer?
>
> Which button would be "defeated"? I wouldn't mind a workaround that
> "cleared" the clicked button and made it ready for being clicked again in
> sequence.
>
> Larry
>
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Larry,
> >
> > You could, but that would defeat the object of the button and you would be
> > in the same position that you are in now, mistakes require starting again.
> >
> > --
> >
> > HTH
> >
> > RP
> >
> > "L Mehl" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Bob --
> > >
> > > Thanks for responding. That would work, but it would add a step for the
> > > user (for each "real" button clicked).
> > >
> > > Is it possible to hide your suggested button and write code to "click"

> that
> > > button every time a "real" button is clicked?
> > >
> > > Larry
> > >
> > > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > > news:#(E-Mail Removed)...
> > > > Not really sure about what your problem is, but how about having a

> command
> > > > button on the userform that the user clicks when they are happy they

> have
> > > > made the correct selection from the listbox.
> > > >
> > > > --
> > > >
> > > > HTH
> > > >
> > > > RP
> > > >
> > > > "L Mehl" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > Hello --
> > > > >
> > > > > I have 3 command buttons (btnA, btnB, btnC) on a worksheet, each

> performing
> > > > > the same task on 3 different columns:
> > > > > - Click button
> > > > > - show UserForm (contains only a listbox)
> > > > > - click listbox item
> > > > > - selected item is assigned to a cell below the button; form closes
> > > > >
> > > > > Each button works fine if btnB is clicked, for example, after btnA.
> > > > >
> > > > > Problem: btnA will not show the UserForm if clicked immediately

> after
> > > > > clicking btnA the first time.
> > > > > The user might have made a mistake and wants to select a different

> item
> from
> > > > > the listbox; I don't want him/her to have to click another button

> just
> to
> > > > > make the desired one "active" again.
> > > > >
> > > > > Code for listbox Click event is:
> > > > >
> > > > > Private Sub lstSelectComponent_Click()
> > > > > 'clicking a model in listbox selects the model ID
> > > > > Dim strCellEqpSelName As String 'range name of cell holding

> selected
> > > > > eqp name
> > > > > strCellEqpSelName = "sel_" & g_strCellEqpSel
> > > > > Cells.Range(strCellEqpSelName).Value =

> Me.lstSelectComponent.Value
> > > > > frmSelectComponent.Hide
> > > > > Exit Sub
> > > > > End Sub
> > > > >
> > > > > Can someone tell me what is wrong with my approach? Is there some

> code
> > > > > needed to "re-activate" the clicked button?
> > > > >
> > > > > Thanks for any help.
> > > > >
> > > > > Larry Mehl
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

 
Reply With Quote
 
L Mehl
Guest
Posts: n/a
 
      15th Oct 2004
Vic --

Your hunch was 100% accurate. The buttons work like a charm. Thank you
very much for responding.

That fix will make me look good in a meeting today.

Larry

"Vic Eldridge" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Larry,
>
> I have a hunch there's some other code in your Userform's Initialise event
> that makes a difference.
>
> Try replacing
> frmSelectComponent.Hide
> with
> Unload frmSelectComponent
>
>
> Regards,
> Vic Eldridge
>
>
> "L Mehl" <(E-Mail Removed)> wrote in message

news:<(E-Mail Removed)>...
> > Bob --
> >
> > What is the mistake to which you refer?
> >
> > Which button would be "defeated"? I wouldn't mind a workaround that
> > "cleared" the clicked button and made it ready for being clicked again

in
> > sequence.
> >
> > Larry
> >
> > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Larry,
> > >
> > > You could, but that would defeat the object of the button and you

would be
> > > in the same position that you are in now, mistakes require starting

again.
> > >
> > > --
> > >
> > > HTH
> > >
> > > RP
> > >
> > > "L Mehl" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > Bob --
> > > >
> > > > Thanks for responding. That would work, but it would add a step for

the
> > > > user (for each "real" button clicked).
> > > >
> > > > Is it possible to hide your suggested button and write code to

"click"
> > that
> > > > button every time a "real" button is clicked?
> > > >
> > > > Larry
> > > >
> > > > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > > > news:#(E-Mail Removed)...
> > > > > Not really sure about what your problem is, but how about having a

> > command
> > > > > button on the userform that the user clicks when they are happy

they
> > have
> > > > > made the correct selection from the listbox.
> > > > >
> > > > > --
> > > > >
> > > > > HTH
> > > > >
> > > > > RP
> > > > >
> > > > > "L Mehl" <(E-Mail Removed)> wrote in message
> > > > > news:(E-Mail Removed)...
> > > > > > Hello --
> > > > > >
> > > > > > I have 3 command buttons (btnA, btnB, btnC) on a worksheet, each

> > performing
> > > > > > the same task on 3 different columns:
> > > > > > - Click button
> > > > > > - show UserForm (contains only a listbox)
> > > > > > - click listbox item
> > > > > > - selected item is assigned to a cell below the button; form

closes
> > > > > >
> > > > > > Each button works fine if btnB is clicked, for example, after

btnA.
> > > > > >
> > > > > > Problem: btnA will not show the UserForm if clicked immediately

> > after
> > > > > > clicking btnA the first time.
> > > > > > The user might have made a mistake and wants to select a

different
> > item
> > from
> > > > > > the listbox; I don't want him/her to have to click another

button
> > just
> > to
> > > > > > make the desired one "active" again.
> > > > > >
> > > > > > Code for listbox Click event is:
> > > > > >
> > > > > > Private Sub lstSelectComponent_Click()
> > > > > > 'clicking a model in listbox selects the model ID
> > > > > > Dim strCellEqpSelName As String 'range name of cell

holding
> > selected
> > > > > > eqp name
> > > > > > strCellEqpSelName = "sel_" & g_strCellEqpSel
> > > > > > Cells.Range(strCellEqpSelName).Value =

> > Me.lstSelectComponent.Value
> > > > > > frmSelectComponent.Hide
> > > > > > Exit Sub
> > > > > > End Sub
> > > > > >
> > > > > > Can someone tell me what is wrong with my approach? Is there

some
> > code
> > > > > > needed to "re-activate" the clicked button?
> > > > > >
> > > > > > Thanks for any help.
> > > > > >
> > > > > > Larry Mehl
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button to execute a Function AJOLSON Microsoft Access Form Coding 1 16th Dec 2008 04:51 PM
Command Button / Macro won't execute properly drumsab Microsoft Excel Programming 4 27th Nov 2007 06:05 PM
Command button code does not execute twlove@ontuet.com Microsoft Excel Programming 2 3rd Jun 2007 06:49 PM
Macro won't execute from a Command Button =?Utf-8?B?RGljayBTY2hlaWJl?= Microsoft Excel Programming 5 19th Aug 2005 01:39 AM
How do I execute command from button or hyperlink? rerhart Microsoft Excel Misc 1 18th Feb 2005 09:41 PM


Features
 

Advertising
 

Newsgroups
 


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