ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   form inside a loop (https://www.excelbanter.com/excel-programming/383923-form-inside-loop.html)

matt

form inside a loop
 
I have a form that includes a number of inputs (we'll call it (name)
frmPO). The user inputs the information from a purchase order (i.e.
company name, address, etc.) into frmPO. One of the text boxes (i.e.
(name) txtPOItems) on frmPO includes an input for the number of items
included in the purchase order.

More than simply entering the number of items, I want the user to be
able to enter the description of the item. I'm getting hung up on
coding something that will allow the user to input the item
description according to the number of items (whether 2 items or 15
items, etc.).

Let me try to illustrate. I'll use the number 3 (i.e.
frmPO.txtPOItems.Value is 3). Initially I thought that when the user
submits the purchase order items (i.e. clicks a command button (name)
cmdEnterItems) the event would trigger another form (i.e.
frmItems.Show) that would allow the user to enter item 1 description
into a text box (i.e txtItems). Upon submitting frmItems (i.e. clicks
the command button (name) cmdSubmitItem) the frmItems would appear
again, the user would enter item 2 description into the text box
(txtItem), submit the form (cmdSubmitItem), frmItems would reappear,
and the user would enter item 3 description (and so on for any number
of items). After entering the 3 items, the user would finish filling
out frmPO and then submit the form. Hopefully this makes sense.

I have written the code below, but when frmAddItem.Show executes I
don't know how to then create the event on frmAddItem such that it
will remember what number in the loop it's on to retain the
appropriate txtItem.Value (which I thought I could do with an array
for outputting purposes in the spreadsheet).

Private Sub cmdEnterItems_Click()
Dim a

For a = 1 To frmPO.txtPOItems.Value
frmAddItem.Show

Next
End Sub

What to do here?

Private Sub cmdSubmitItem_Click()
'I'm not sure what to do here. Maybe somehow pass the txtItem back
to the above procedure
'such that it is received inside the For Loop?
End Sub

Any help is greatly appreciated as I learn more about user forms and
programming in general. Thanks in advance.

Matt


Bob Phillips

form inside a loop
 
Something like this

Dim AryDesc

Private Sub cmdEnterItems_Click()
Dim a As Long

With Me
ReDim AryDesc(1 To .txtPOItems.Value)
For a = 1 To .txtPOItems.Value
frmAddItem.lblItems.Caption = "Description " & a
frmAddItem.txtItems.Text = ""
frmAddItem.Show
AryDesc(a) = frmAddItem.txtItems.Text
Next
End With
End Sub

in frmPO, and

Private Sub cmdSubmitItem_Click()

Me.Hide

End Sub

in frmAddItems.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"matt" wrote in message
oups.com...
I have a form that includes a number of inputs (we'll call it (name)
frmPO). The user inputs the information from a purchase order (i.e.
company name, address, etc.) into frmPO. One of the text boxes (i.e.
(name) txtPOItems) on frmPO includes an input for the number of items
included in the purchase order.

More than simply entering the number of items, I want the user to be
able to enter the description of the item. I'm getting hung up on
coding something that will allow the user to input the item
description according to the number of items (whether 2 items or 15
items, etc.).

Let me try to illustrate. I'll use the number 3 (i.e.
frmPO.txtPOItems.Value is 3). Initially I thought that when the user
submits the purchase order items (i.e. clicks a command button (name)
cmdEnterItems) the event would trigger another form (i.e.
frmItems.Show) that would allow the user to enter item 1 description
into a text box (i.e txtItems). Upon submitting frmItems (i.e. clicks
the command button (name) cmdSubmitItem) the frmItems would appear
again, the user would enter item 2 description into the text box
(txtItem), submit the form (cmdSubmitItem), frmItems would reappear,
and the user would enter item 3 description (and so on for any number
of items). After entering the 3 items, the user would finish filling
out frmPO and then submit the form. Hopefully this makes sense.

I have written the code below, but when frmAddItem.Show executes I
don't know how to then create the event on frmAddItem such that it
will remember what number in the loop it's on to retain the
appropriate txtItem.Value (which I thought I could do with an array
for outputting purposes in the spreadsheet).

Private Sub cmdEnterItems_Click()
Dim a

For a = 1 To frmPO.txtPOItems.Value
frmAddItem.Show

Next
End Sub

What to do here?

Private Sub cmdSubmitItem_Click()
'I'm not sure what to do here. Maybe somehow pass the txtItem back
to the above procedure
'such that it is received inside the For Loop?
End Sub

Any help is greatly appreciated as I learn more about user forms and
programming in general. Thanks in advance.

Matt




matt

form inside a loop
 
On Feb 26, 2:28 am, "Bob Phillips" wrote:
Something like this

Dim AryDesc

Private Sub cmdEnterItems_Click()
Dim a As Long

With Me
ReDim AryDesc(1 To .txtPOItems.Value)
For a = 1 To .txtPOItems.Value
frmAddItem.lblItems.Caption = "Description " & a
frmAddItem.txtItems.Text = ""
frmAddItem.Show
AryDesc(a) = frmAddItem.txtItems.Text
Next
End With
End Sub

in frmPO, and

Private Sub cmdSubmitItem_Click()

Me.Hide

End Sub

in frmAddItems.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"matt" wrote in message

oups.com...



I have a form that includes a number of inputs (we'll call it (name)
frmPO). The user inputs the information from a purchase order (i.e.
company name, address, etc.) into frmPO. One of the text boxes (i.e.
(name) txtPOItems) on frmPO includes an input for the number of items
included in the purchase order.


More than simply entering the number of items, I want the user to be
able to enter the description of the item. I'm getting hung up on
coding something that will allow the user to input the item
description according to the number of items (whether 2 items or 15
items, etc.).


Let me try to illustrate. I'll use the number 3 (i.e.
frmPO.txtPOItems.Value is 3). Initially I thought that when the user
submits the purchase order items (i.e. clicks a command button (name)
cmdEnterItems) the event would trigger another form (i.e.
frmItems.Show) that would allow the user to enter item 1 description
into a text box (i.e txtItems). Upon submitting frmItems (i.e. clicks
the command button (name) cmdSubmitItem) the frmItems would appear
again, the user would enter item 2 description into the text box
(txtItem), submit the form (cmdSubmitItem), frmItems would reappear,
and the user would enter item 3 description (and so on for any number
of items). After entering the 3 items, the user would finish filling
out frmPO and then submit the form. Hopefully this makes sense.


I have written the code below, but when frmAddItem.Show executes I
don't know how to then create the event on frmAddItem such that it
will remember what number in the loop it's on to retain the
appropriate txtItem.Value (which I thought I could do with an array
for outputting purposes in the spreadsheet).


Private Sub cmdEnterItems_Click()
Dim a


For a = 1 To frmPO.txtPOItems.Value
frmAddItem.Show


Next
End Sub


What to do here?


Private Sub cmdSubmitItem_Click()
'I'm not sure what to do here. Maybe somehow pass the txtItem back
to the above procedure
'such that it is received inside the For Loop?
End Sub


Any help is greatly appreciated as I learn more about user forms and
programming in general. Thanks in advance.


Matt- Hide quoted text -


- Show quoted text -


Bob,

Thank you very much; I appreciate it. The code works very well.

Matt



All times are GMT +1. The time now is 04:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com