Thread: Creating a loop
View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Jennifer Jennifer is offline
external usenet poster
 
Posts: 385
Default Creating a loop

I am pretty confused
I am getting the error message: Member or data member not found for this line
myTBVal = Me.OLEObjects("Textbox" & iCtr).Object.Value

To explain just a bit further I am working in a form, the user selects a
fruit from a combo box when he makes this selection a label (lblTotal) is
then filled with the boxes of inventory on hand of that fruit. From there the
user clicks into textboxes (13 possible) and enters how many he wants to send
to each market. There is a text box for each market. As he enters for example
30 in txtbox1 i would like that number (30) to be subtracted from the total
inventory number and reflected in the lblTotal. This may have made it more
confusing. Thank you for the help. Jennifer
--
Thank you,

Jennifer


"Dave Peterson" wrote:

I'm not sure what you're doing or where your controls are...

But I guessed that the textboxes (from the Control toolbox toolbar) were on the
same worksheet as the label.

I put 13 textboxes on a worksheet, a label and a commandbutton (all from the
control toolbox toolbar).

This is the code under the commandbutton:

Option Explicit
Private Sub CommandButton1_Click()

Dim iCtr As Long
Dim myTBSum As Double
Dim myTBVal As String

myTBSum = 0

For iCtr = 1 To 13
myTBVal = Me.OLEObjects("Textbox" & iCtr).Object.Value
If IsNumeric(myTBVal) Then
myTBSum = myTBSum + myTBVal
Else
Beep
End If
Next iCtr

Me.Label1.Caption = Format(myTBSum, "0.00")

End Sub

Maybe it'll give you an idea???

Jennifer wrote:

Thanks a bunch-
Close but I am getting a few errors in getting those I tried to problem
solve the best I understand and this is where I am stuck: Thank you a bunch!

Dim Ration As Variant
Dim Percent As String

With Worksheets("Database")
Ration = txtRFID.Value
'Sheets("Rations").Activate
Percent = WorksheetFunction. _
SumIf(Range("ProduceItemDatabase"), Ration, Range("BxsToMarket"))
TBarr = Array(TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, _
TextBox6, TextBox7, TextBox8, TextBox9, TextBox10, TextBox11, _
TextBox12, TextBox13)
For i = 0 To 12
If Me.TextBox1.Value = "" Then
Exit Sub
Else
Me.lblTotal = Percent - TBarr(i).Value ********It is saying
type mismatch
End If
Next
End With
End Sub--
Thank you,

Jennifer

"JLGWhiz" wrote:

Already see one goof. Should be For i = 0 To 12 instead of 13.
The array is zero based.

"Jennifer" wrote:

Hi Guys,
Can you help?
I have created this code but I have never created a loop before so I need
some direction:
I have 13 text boxes I need it to check for a value and subtract it from the
'percent'
Thank you, Jennifer

Private Sub GetSum1()
Dim Ration As Variant
Dim Percent As String
With Worksheets("Database")
Ration = txtRFID.Value
'Sheets("Rations").Activate
Percent = WorksheetFunction. _
SumIf(Range("ProduceItemDatabase"), Ration, Range("BxsToMarket"))
If Me.TextBox1 = "" Then
Exit Sub
Else
Me.lblTotal = Percent - TextBox1.Value
End If

End With
End Sub

--
Thank you,

Jennifer


--

Dave Peterson