PDA

View Full Version : Solved: Add Labels Together



Emoncada
06-16-2009, 07:56 AM
I have this code that worked with Txtboxes but I changed the TxtBoxes to Labels.

This is the code I am trying to use.
Private Sub Add()
Dim tmp
If Not LblQty1.Caption = "" Then
tmp = tmp + CDbl(LblQty1.Caption)
End If

If Not LblQty2.Caption = "" Then
tmp = tmp + CDbl(LblQty2.Caption)
End If

If Not LblQty3.Caption = "" Then
tmp = tmp + CDbl(LblQty3.Caption)
End If

If Not LblQty4.Caption = "" Then
tmp = tmp + CDbl(LblQty4.Caption)
End If

If Not LblQty5.Caption = "" Then
tmp = tmp + CDbl(LblQty5.Caption)
End If

UserFormOutgoing.LblTotal.Caption = tmp
End Sub

Private Sub LblQty1_Change()
Add
End Sub
Private Sub LblQty2_Change()
Add
End Sub
Private Sub LblQty3_Change()
Add
End Sub
Private Sub LblQty4_Change()
Add
End Sub
Private Sub LblQty5_Change()
Add
End Sub

The LbtQty will always be 1 or "".

Any help or suggestions would be great thanks.

Bob Phillips
06-16-2009, 09:36 AM
Labels don't have a Change event, so how are you doing it?

Emoncada
06-16-2009, 09:51 AM
No I can't. It worked with Txtboxes so I was trying to make it work with Labels because I don't want the user to make changes to it so it can auto populate.

Is there another way of making this happen?

Bob Phillips
06-16-2009, 09:54 AM
Labels are just that, labels. They are not changeable by the user. Why do you want to change?

Emoncada
06-16-2009, 09:59 AM
No I don't want the user to make changes to that, that's why I made them Labels. I can put it back as a TextBox and use the change add action, have the txtbox disabled but then the 1 looks faded.

Do you know a way I can fix that?

Bob Phillips
06-16-2009, 10:02 AM
I am confused. If you don't want the user to change them, then you must be setting the captions in your code, so why test the value and add, why not just set the value of the total label?

Emoncada
06-16-2009, 10:08 AM
Yes I have 5 lines each containing a Qty which is preset in the code.
So If CmbBoxSN1 in line 1 <> "" then LblQty1 = "1"
If CmbBoxSN2 in line 2 <> "" then LblQty2 = "1"
etc...

Then I have the LblTotal.Caption = (Total Qty)

Im just testing the CmbBoxSN boxes if it has a value then Qty=1 else ""
I just want to show on form the qty.
If it's easier to have LblTotal look at the CmbBoxSN's and come up with the total that will also work.

Hope that explains my goal.

Bob Phillips
06-16-2009, 10:22 AM
So I would just add all the captions together whenever I tested the combo value and set the total.

That is pretty simple is it not?

Emoncada
06-16-2009, 10:26 AM
Yes The CmbBoxSN1 value is not a number but Text&Numbers, but as long as the Combo Value has any Text (Serial Number) then Qty for that line would be a "1".

Then have the LblTotal.Caption show a "1" and change it to "2" if the next CmbBoxSN2 value has a value also.

Emoncada
06-16-2009, 10:47 AM
I did something like this
LblQty1.Caption + LblQty2.Caption + LblQty3.Caption + LblQty4.Caption + LblQty5.Caption

seems like im on the right track but instead of adding them it's putting them next to each other so instead of "2" it's giving me 11

Bob Phillips
06-16-2009, 10:58 AM
Isn't it as simple as



If CmbBoxSN1.Value <> "" Then LblTotal.Caption = 1
If CmbBoxSN2.Value <> "" Then LblTotal.Caption = LblTotal.Caption + 1
'etc

Emoncada
06-16-2009, 11:08 AM
Perfect XLD.

That seemed simple after seeing it in code. Thanks