PDA

View Full Version : Form vb change help



Emoncada
05-14-2007, 07:43 AM
I have this script that works great

Private Sub Cmd17IN_Click()
LoadTextBoxes "HP 17IN. TFT L1706", "", "1"
add
End Sub
Private Sub CmdNC8230_Click()
LoadTextBoxes "HP NC8230", "", "1"
LoadTextBoxes "LAPTOP BAG", "Expense", "1"
LoadTextBoxes "KEYBOARD", "Expense", "1"
LoadTextBoxes "MOUSE", "Expense", "1"
LoadTextBoxes "PORT REPLICATOR", "Expense", "1"
add
End Sub
Private Sub CmdNC8430_Click()
LoadTextBoxes "HP NC8430", "", "1"
LoadTextBoxes "LAPTOP BAG", "Expense", "1"
LoadTextBoxes "KEYBOARD", "Expense", "1"
LoadTextBoxes "MOUSE", "Expense", "1"
LoadTextBoxes "PORT REPLICATOR", "Expense", "1"
add
End Sub

Private Sub LoadTextBoxes(TB1, TB2, TB3)
Dim ctl As MSForms.Control
Dim i As Long
With Me
For i = 1 To 18
If .Controls("TxtDesc" & i) = "" Then
.Controls("TxtDesc" & i).Text = TB1
.Controls("TxtSN" & i).Text = TB2
.Controls("TxtQua" & i).Text = TB3
Exit For
End If
Next i
End With
End Sub

Private Sub add()
Dim tmp
If Not TxtQua1.Text = "" Then
tmp = tmp + CDbl(TxtQua1.Text)
End If
If Not TxtQua2.Text = "" Then
tmp = tmp + CDbl(TxtQua2.Text)
End If
If Not TxtQua3.Text = "" Then
tmp = tmp + CDbl(TxtQua3.Text)
End If
If Not TxtQua4.Text = "" Then
tmp = tmp + CDbl(TxtQua4.Text)
End If
If Not TxtQua5.Text = "" Then
tmp = tmp + CDbl(TxtQua5.Text)
End If
If Not TxtQua6.Text = "" Then
tmp = tmp + CDbl(TxtQua6.Text)
End If
If Not TxtQua7.Text = "" Then
tmp = tmp + CDbl(TxtQua7.Text)
End If
If Not TxtQua8.Text = "" Then
tmp = tmp + CDbl(TxtQua8.Text)
End If
If Not TxtQua9.Text = "" Then
tmp = tmp + CDbl(TxtQua9.Text)
End If
If Not TxtQua10.Text = "" Then
tmp = tmp + CDbl(TxtQua10.Text)
End If
If Not TxtQua11.Text = "" Then
tmp = tmp + CDbl(TxtQua11.Text)
End If
If Not TxtQua12.Text = "" Then
tmp = tmp + CDbl(TxtQua12.Text)
End If
If Not TxtQua13.Text = "" Then
tmp = tmp + CDbl(TxtQua13.Text)
End If
If Not TxtQua14.Text = "" Then
tmp = tmp + CDbl(TxtQua14.Text)
End If
If Not TxtQua15.Text = "" Then
tmp = tmp + CDbl(TxtQua15.Text)
End If
If Not TxtQua16.Text = "" Then
tmp = tmp + CDbl(TxtQua16.Text)
End If
If Not TxtQua17.Text = "" Then
tmp = tmp + CDbl(TxtQua17.Text)
End If
If Not TxtQua18.Text = "" Then
tmp = tmp + CDbl(TxtQua18.Text)
End If
UserForm1.LblTotal.Caption = tmp
End Sub


Only problem is now I had to change TxtDesc1 - TxtDesc18 to CmbBoxDesc1 - CmbBoxDesc18. How can I make that work with this that same way it did for the Txt Boxes?

Emoncada
05-14-2007, 07:48 AM
My main problem with be this part
Private Sub LoadTextBoxes(TB1, TB2, TB3)
Dim ctl As MSForms.Control
Dim i As Long
With Me
For i = 1 To 18
If .Controls("TxtDesc" & i) = "" Then
.Controls("TxtDesc" & i).Text = TB1
.Controls("TxtSN" & i).Text = TB2
.Controls("TxtQua" & i).Text = TB3
Exit For
End If
Next i
End With
End Sub

I just wanted everyone to know what add() was doing but didn't want to confuse.

Bob Phillips
05-14-2007, 08:05 AM
Just change "Txt to "cmbBox, .Text to .Value

Emoncada
05-14-2007, 08:08 AM
I was going to try that but didn't think it would be that easy. Thanks again XLD.