Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default summing text boxes but do't include disabled ones??

Hi again,
I have a command button (cmdsubtotal) which adds 8 text boxes. I got the
following code from a post a few weeks ago and it works perfectly - thank you!

Private Sub cmdsubtotal_Click()

Dim MyTotal As Double
MyTotal = 0
If IsNumeric(Trim(Me.txtprice1.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice1.Value)
End If
If IsNumeric(Trim(Me.txtprice2.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice2.Value)
End If
If IsNumeric(Trim(Me.txtprice3.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice3.Value)
End If
If IsNumeric(Trim(Me.txtprice4.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice4.Value)
End If
If IsNumeric(Trim(Me.txtprice5.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice5.Value)
End If
If IsNumeric(Trim(Me.txtprice6.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice6.Value)
End If
If IsNumeric(Trim(Me.txtprice7.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice7.Value)
End If
If IsNumeric(Trim(Me.txtprice8.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice8.Value)
End If

Me.txtSubTotal.Value = MyTotal

End Sub

No I have added some check boxes which disable the corresponding text box
when ticked.
How can I adjust the code above to NOT include the text box value if it has
been disabled?

Thanks in advance :)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default summing text boxes but do't include disabled ones??

hi
i think all you would have to do is add another if to test if the check box
is checked.
Private Sub cmdsubtotal_Click()

Dim MyTotal As Double
MyTotal = 0
If Me.checkbox1.value = true then ' it's checked
If IsNumeric(Trim(Me.txtprice1.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice1.Value)
End If
End If
'etc. etc.
'work your way down the text/check boxes.
end sub

untested but if the check box value is false, it should skip the rest of the
clause.
try it. post back if it don't work.

regards
FSt1

"Rachel" wrote:

Hi again,
I have a command button (cmdsubtotal) which adds 8 text boxes. I got the
following code from a post a few weeks ago and it works perfectly - thank you!

Private Sub cmdsubtotal_Click()

Dim MyTotal As Double
MyTotal = 0
If IsNumeric(Trim(Me.txtprice1.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice1.Value)
End If
If IsNumeric(Trim(Me.txtprice2.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice2.Value)
End If
If IsNumeric(Trim(Me.txtprice3.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice3.Value)
End If
If IsNumeric(Trim(Me.txtprice4.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice4.Value)
End If
If IsNumeric(Trim(Me.txtprice5.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice5.Value)
End If
If IsNumeric(Trim(Me.txtprice6.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice6.Value)
End If
If IsNumeric(Trim(Me.txtprice7.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice7.Value)
End If
If IsNumeric(Trim(Me.txtprice8.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice8.Value)
End If

Me.txtSubTotal.Value = MyTotal

End Sub

No I have added some check boxes which disable the corresponding text box
when ticked.
How can I adjust the code above to NOT include the text box value if it has
been disabled?

Thanks in advance :)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default summing text boxes but do't include disabled ones??

Rachel,
see if this does what you want:

Private Sub cmdsubtotal_Click()
Dim Ctl As Control
Dim i As Integer
Dim MyTotal As Double

MyTotal = 0

For i = 1 To 8

Set Ctl = Me.Controls("txtprice" & i)

If IsNumeric(Trim(Ctl.Value)) Then

With Ctl

If .Enabled = True Then

MyTotal = _
MyTotal + Trim(Me.Controls("txtprice" & i).Value)

Else

Me.Controls("txtprice" & i).Text = 0

End If

End With

Else

Me.Controls("txtprice" & i).Text = ""

End If

Next i

Me.txtSubTotal.Value = MyTotal

End Sub

--
jb


"Rachel" wrote:

Hi again,
I have a command button (cmdsubtotal) which adds 8 text boxes. I got the
following code from a post a few weeks ago and it works perfectly - thank you!

Private Sub cmdsubtotal_Click()

Dim MyTotal As Double
MyTotal = 0
If IsNumeric(Trim(Me.txtprice1.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice1.Value)
End If
If IsNumeric(Trim(Me.txtprice2.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice2.Value)
End If
If IsNumeric(Trim(Me.txtprice3.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice3.Value)
End If
If IsNumeric(Trim(Me.txtprice4.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice4.Value)
End If
If IsNumeric(Trim(Me.txtprice5.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice5.Value)
End If
If IsNumeric(Trim(Me.txtprice6.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice6.Value)
End If
If IsNumeric(Trim(Me.txtprice7.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice7.Value)
End If
If IsNumeric(Trim(Me.txtprice8.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice8.Value)
End If

Me.txtSubTotal.Value = MyTotal

End Sub

No I have added some check boxes which disable the corresponding text box
when ticked.
How can I adjust the code above to NOT include the text box value if it has
been disabled?

Thanks in advance :)

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 113
Default summing text boxes but do't include disabled ones??

John - spot on as always!! thank you.
I really appreciate you taking the time to answer all my questions. I never
would be able to work these things out myself!!

"john" wrote:

Rachel,
see if this does what you want:

Private Sub cmdsubtotal_Click()
Dim Ctl As Control
Dim i As Integer
Dim MyTotal As Double

MyTotal = 0

For i = 1 To 8

Set Ctl = Me.Controls("txtprice" & i)

If IsNumeric(Trim(Ctl.Value)) Then

With Ctl

If .Enabled = True Then

MyTotal = _
MyTotal + Trim(Me.Controls("txtprice" & i).Value)

Else

Me.Controls("txtprice" & i).Text = 0

End If

End With

Else

Me.Controls("txtprice" & i).Text = ""

End If

Next i

Me.txtSubTotal.Value = MyTotal

End Sub

--
jb


"Rachel" wrote:

Hi again,
I have a command button (cmdsubtotal) which adds 8 text boxes. I got the
following code from a post a few weeks ago and it works perfectly - thank you!

Private Sub cmdsubtotal_Click()

Dim MyTotal As Double
MyTotal = 0
If IsNumeric(Trim(Me.txtprice1.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice1.Value)
End If
If IsNumeric(Trim(Me.txtprice2.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice2.Value)
End If
If IsNumeric(Trim(Me.txtprice3.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice3.Value)
End If
If IsNumeric(Trim(Me.txtprice4.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice4.Value)
End If
If IsNumeric(Trim(Me.txtprice5.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice5.Value)
End If
If IsNumeric(Trim(Me.txtprice6.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice6.Value)
End If
If IsNumeric(Trim(Me.txtprice7.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice7.Value)
End If
If IsNumeric(Trim(Me.txtprice8.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice8.Value)
End If

Me.txtSubTotal.Value = MyTotal

End Sub

No I have added some check boxes which disable the corresponding text box
when ticked.
How can I adjust the code above to NOT include the text box value if it has
been disabled?

Thanks in advance :)

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default summing text boxes but do't include disabled ones??

Hi Rachel,
you are most welcome & thanks for your feedback.
Just in case you have not seen it, I updated your lookup function post.
--
jb


"Rachel" wrote:

John - spot on as always!! thank you.
I really appreciate you taking the time to answer all my questions. I never
would be able to work these things out myself!!

"john" wrote:

Rachel,
see if this does what you want:

Private Sub cmdsubtotal_Click()
Dim Ctl As Control
Dim i As Integer
Dim MyTotal As Double

MyTotal = 0

For i = 1 To 8

Set Ctl = Me.Controls("txtprice" & i)

If IsNumeric(Trim(Ctl.Value)) Then

With Ctl

If .Enabled = True Then

MyTotal = _
MyTotal + Trim(Me.Controls("txtprice" & i).Value)

Else

Me.Controls("txtprice" & i).Text = 0

End If

End With

Else

Me.Controls("txtprice" & i).Text = ""

End If

Next i

Me.txtSubTotal.Value = MyTotal

End Sub

--
jb


"Rachel" wrote:

Hi again,
I have a command button (cmdsubtotal) which adds 8 text boxes. I got the
following code from a post a few weeks ago and it works perfectly - thank you!

Private Sub cmdsubtotal_Click()

Dim MyTotal As Double
MyTotal = 0
If IsNumeric(Trim(Me.txtprice1.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice1.Value)
End If
If IsNumeric(Trim(Me.txtprice2.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice2.Value)
End If
If IsNumeric(Trim(Me.txtprice3.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice3.Value)
End If
If IsNumeric(Trim(Me.txtprice4.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice4.Value)
End If
If IsNumeric(Trim(Me.txtprice5.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice5.Value)
End If
If IsNumeric(Trim(Me.txtprice6.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice6.Value)
End If
If IsNumeric(Trim(Me.txtprice7.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice7.Value)
End If
If IsNumeric(Trim(Me.txtprice8.Value)) Then
MyTotal = MyTotal + Trim(Me.txtprice8.Value)
End If

Me.txtSubTotal.Value = MyTotal

End Sub

No I have added some check boxes which disable the corresponding text box
when ticked.
How can I adjust the code above to NOT include the text box value if it has
been disabled?

Thanks in advance :)

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
30 CHECK BOXES to be disabled CAPTGNVR[_2_] Excel Programming 8 September 29th 08 02:45 PM
Macro - To Include Summing All Similar Entries steven.holloway Excel Discussion (Misc queries) 1 December 24th 07 02:07 PM
Summing two text boxes on a form - HELP! Co-op Bank Excel Programming 1 November 28th 06 11:10 AM
Summing the values in text boxes cosmic mo Excel Programming 4 March 17th 06 05:20 PM
disabled check boxes chinita Excel Discussion (Misc queries) 3 June 18th 05 06:07 PM


All times are GMT +1. The time now is 11:58 AM.

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

About Us

"It's about Microsoft Excel"