Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Using command buttons change the value in a form text box.

The subs below are each run from 2 command buttons on a form, Machine
Hours and Labour Hours. When the form is initially loaded it is with
Machine hours in the txtMilla thru txtMille text boxes . The operator
can then change from Machine Hours to Labour Hours by clicking the
Labour Hours command button, likewise the operator can change the
Labour Hours back to Machine Hours by clicking the Machine Hours
command button.

I need to overcome the problem of subsequence clicks on the same
command button, for example, if the labour hours were clicked twice one
could never get back to the original value of machine hours when the
machine hours button is clicked.

How would you code these such that after the labour hours command
button is clicked it is somewhat disabled until the machine hours has
been clicked. Or better yet can this be run from the same command
button, as on initial loading of the form it displays Machine Hours in
the text boxes, the command button caption could say Machine hours, but
when pressed it would convert the values in the text boxes to Labour
hours and display Labour Hours in the caption, then obvoiusly on
subsequent clicks it would toggle between the two, but the values
maintain integrity, any thoughts.

Private Sub LabourHours_Click()

Factor = 2.5
MachineHours.Font.Bold = False
LabourHours.Font.Bold = True

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor

End Sub

Private Sub MachineHours_Click()

Factor = 2.5
LabourHours.Font.Bold = False
MachineHours.Font.Bold = True

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * (1 /
Factor)
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * (1 /
Factor)
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * (1 /
Factor)
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * (1 /
Factor)
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * (1 /
Factor)

End Sub

Regards
burl_h

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Using command buttons change the value in a form text box.

Hi Burl

There are a number of options but you need some type of flag to indicate the
current status of the hours (machine or labour).

1. You can you two buttons and disable the other option
2. You could have one button and switch the caption
3. You could use a global flag and check the status on the button press.

Lets look at 1.

In you startup code

set the

me.LabourHours.enabled = true
me.MachineHours.enabled = false

then you need to switch the buttons when they are clicked:

const Factor as double = 2.5

Private Sub LabourHours_Click()

me.MachineHours.enabled= true
me.LabourHours.enabled = false

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor

End Sub

Private Sub MachineHours_Click()

me.MachineHours.enabled= false
me.LabourHours.enabled = true

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor

End Sub

If you want one button and switch the text use say LabourHours

LabourHours.caption = "Switch to Labour Hours"

This i would set in the initialize section to make sure you get the text
correct:

Private Sub UserForm_Initialize()
me.LabourHours.caption = "Switch to Labour Hours"
End Sub


then you need to the following:

const Factor as double = 2.5
const szLab as string ="Switch to Labour Hours"
const szMc as string ="Switch to Macine Hours"

Private Sub LabourHours_Click()
if me.LabourHours.caption = szLab then
' switch to labour
me.LabourHours.caption = szMc ' switch text
frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor
else
' switch to machine
me.LabourHours.caption = szLab ' switch text
frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor
end if
End Sub


The last option is a global flag

define at the top of the module

dim bFlagLab as boolean

in the initialize section

bflagLab=true

then in each routine add

for lab

if bflagLab=true then
bflaglab=false
else
beep
exit sub
end if

for machine

if bflagLab=false then
bflaglab=true
else
beep
exit sub
end if


The last one may be the wrong way round.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"burl_h" wrote:

The subs below are each run from 2 command buttons on a form, Machine
Hours and Labour Hours. When the form is initially loaded it is with
Machine hours in the txtMilla thru txtMille text boxes . The operator
can then change from Machine Hours to Labour Hours by clicking the
Labour Hours command button, likewise the operator can change the
Labour Hours back to Machine Hours by clicking the Machine Hours
command button.

I need to overcome the problem of subsequence clicks on the same
command button, for example, if the labour hours were clicked twice one
could never get back to the original value of machine hours when the
machine hours button is clicked.

How would you code these such that after the labour hours command
button is clicked it is somewhat disabled until the machine hours has
been clicked. Or better yet can this be run from the same command
button, as on initial loading of the form it displays Machine Hours in
the text boxes, the command button caption could say Machine hours, but
when pressed it would convert the values in the text boxes to Labour
hours and display Labour Hours in the caption, then obvoiusly on
subsequent clicks it would toggle between the two, but the values
maintain integrity, any thoughts.

Private Sub LabourHours_Click()

Factor = 2.5
MachineHours.Font.Bold = False
LabourHours.Font.Bold = True

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor

End Sub

Private Sub MachineHours_Click()

Factor = 2.5
LabourHours.Font.Bold = False
MachineHours.Font.Bold = True

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * (1 /
Factor)
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * (1 /
Factor)
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * (1 /
Factor)
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * (1 /
Factor)
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * (1 /
Factor)

End Sub

Regards
burl_h


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Using command buttons change the value in a form text box.

Martin,

Thanks for the 3 solutions, I did try the first 2 and they worked
great, I'm not sure I'll try the 3rd solution, it looks a little
confusing, where the first two were quite simple to implement, thanks
again for your response.

burl_h

Martin Fishlock wrote:
Hi Burl

There are a number of options but you need some type of flag to indicate the
current status of the hours (machine or labour).

1. You can you two buttons and disable the other option
2. You could have one button and switch the caption
3. You could use a global flag and check the status on the button press.

Lets look at 1.

In you startup code

set the

me.LabourHours.enabled = true
me.MachineHours.enabled = false

then you need to switch the buttons when they are clicked:

const Factor as double = 2.5

Private Sub LabourHours_Click()

me.MachineHours.enabled= true
me.LabourHours.enabled = false

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor

End Sub

Private Sub MachineHours_Click()

me.MachineHours.enabled= false
me.LabourHours.enabled = true

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor

End Sub

If you want one button and switch the text use say LabourHours

LabourHours.caption = "Switch to Labour Hours"

This i would set in the initialize section to make sure you get the text
correct:

Private Sub UserForm_Initialize()
me.LabourHours.caption = "Switch to Labour Hours"
End Sub


then you need to the following:

const Factor as double = 2.5
const szLab as string ="Switch to Labour Hours"
const szMc as string ="Switch to Macine Hours"

Private Sub LabourHours_Click()
if me.LabourHours.caption = szLab then
' switch to labour
me.LabourHours.caption = szMc ' switch text
frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor
else
' switch to machine
me.LabourHours.caption = szLab ' switch text
frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value / Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value / Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value / Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value / Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value / Factor
end if
End Sub


The last option is a global flag

define at the top of the module

dim bFlagLab as boolean

in the initialize section

bflagLab=true

then in each routine add

for lab

if bflagLab=true then
bflaglab=false
else
beep
exit sub
end if

for machine

if bflagLab=false then
bflaglab=true
else
beep
exit sub
end if


The last one may be the wrong way round.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"burl_h" wrote:

The subs below are each run from 2 command buttons on a form, Machine
Hours and Labour Hours. When the form is initially loaded it is with
Machine hours in the txtMilla thru txtMille text boxes . The operator
can then change from Machine Hours to Labour Hours by clicking the
Labour Hours command button, likewise the operator can change the
Labour Hours back to Machine Hours by clicking the Machine Hours
command button.

I need to overcome the problem of subsequence clicks on the same
command button, for example, if the labour hours were clicked twice one
could never get back to the original value of machine hours when the
machine hours button is clicked.

How would you code these such that after the labour hours command
button is clicked it is somewhat disabled until the machine hours has
been clicked. Or better yet can this be run from the same command
button, as on initial loading of the form it displays Machine Hours in
the text boxes, the command button caption could say Machine hours, but
when pressed it would convert the values in the text boxes to Labour
hours and display Labour Hours in the caption, then obvoiusly on
subsequent clicks it would toggle between the two, but the values
maintain integrity, any thoughts.

Private Sub LabourHours_Click()

Factor = 2.5
MachineHours.Font.Bold = False
LabourHours.Font.Bold = True

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * Factor
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * Factor
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * Factor
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * Factor
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * Factor

End Sub

Private Sub MachineHours_Click()

Factor = 2.5
LabourHours.Font.Bold = False
MachineHours.Font.Bold = True

frmQuoteForm.txtMilla.Value = frmQuoteForm.txtMilla.Value * (1 /
Factor)
frmQuoteForm.txtMillb.Value = frmQuoteForm.txtMillb.Value * (1 /
Factor)
frmQuoteForm.txtMillc.Value = frmQuoteForm.txtMillc.Value * (1 /
Factor)
frmQuoteForm.txtMilld.Value = frmQuoteForm.txtMilld.Value * (1 /
Factor)
frmQuoteForm.txtMille.Value = frmQuoteForm.txtMille.Value * (1 /
Factor)

End Sub

Regards
burl_h



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
How to Hide Form and Command Buttons until such condition is true? ash3154 Excel Discussion (Misc queries) 0 September 2nd 09 12:37 AM
Cell name to change name in codes of command buttons aussiegirlone Excel Discussion (Misc queries) 0 July 3rd 09 11:16 AM
User form Command Buttons jhyatt Excel Discussion (Misc queries) 3 September 25th 07 04:28 PM
Excel Form With Date Time Picker And Command Buttons Mike Excel Programming 0 November 25th 06 03:14 PM
User Form Option & Command Buttons Information Hog[_2_] Excel Programming 1 August 19th 05 10:00 PM


All times are GMT +1. The time now is 06:16 AM.

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"