ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to store user responses (https://www.excelbanter.com/excel-programming/439765-how-store-user-responses.html)

dan dungan

how to store user responses
 
Using Excel 2000, I have a userform--userform1, with a textbox--
txtquantity1.

I'm trying to get the user to enter the quantity for a part number in
a quote. There could possibly be as many as 40 different quantities
requested by the customer.

When the user enters the quantity and presses enter, I'd like to ask
them if they have another quantity to enter, or at least provide
another textbox so they could enter another quantity and keep
generating textboxes until the user is through adding quantities.

When they are finished entering the last quantity, the user needs to
choose the proper formula and then I need to calculate a price based
on. . . Well this part gets complicated.

Right now I just want to see if I can store the quantities for
calculations later.

I'm trying to use the code below, but it doesn't loop and overwrites
the textbox with the next quantity.

Thank you for your feedback.

Private Sub txtQuantity_1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Message, Title, Default, MyValue
Message = "Enter the next quantity" ' Set prompt.
Title = "Quantity" ' Set title.
Default = "" ' Set default.
' Display message, title, and default value.
Dim Msg, Style, Ttle, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbDefaultButton2 ' Define buttons.

Response = MsgBox(Msg, Style, Ttle, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Set Mycmd = Me.Controls.Add("Forms.TextBox.1", name, True)
MyValue = InputBox(Message, Title, Default)
Mycmd = MyValue

Else ' User chose No.
MyString = "No" ' Perform some action.
End If
End Sub

JLGWhiz[_2_]

how to store user responses
 
I created a user form with a textbox named txtQuantity_1 and a command
button named CommandButton1. I then put the following code in the UserForm
code module and it allowed me to enter quantities in the text box which were
then posted to the active sheet in column A. Give it a try and maybe you
can adapt it to your needs.

Private Sub CommandButton1_Click()
Dim lr As Long, sh As Worksheet
Set sh = ActiveSheet 'Change to actual sheet name
lr = sh.Cells(Rows.Count, "A").End(xlUp).Row
sh.Range("A" & lr + 1) = Me.txtQuantity_1.Text
cont = MsgBox("DO YOU NEED TO MAKE ANOTHER ENTRY?", vbYesNo, "CONTINUE?")
If cont = vbYes Then
Me.txtQuantity_1.Text = ""
Me.txtQuantity_1.SetFocus
End If
End Sub





"dan dungan" wrote in message
...
Using Excel 2000, I have a userform--userform1, with a textbox--
txtquantity1.

I'm trying to get the user to enter the quantity for a part number in
a quote. There could possibly be as many as 40 different quantities
requested by the customer.

When the user enters the quantity and presses enter, I'd like to ask
them if they have another quantity to enter, or at least provide
another textbox so they could enter another quantity and keep
generating textboxes until the user is through adding quantities.

When they are finished entering the last quantity, the user needs to
choose the proper formula and then I need to calculate a price based
on. . . Well this part gets complicated.

Right now I just want to see if I can store the quantities for
calculations later.

I'm trying to use the code below, but it doesn't loop and overwrites
the textbox with the next quantity.

Thank you for your feedback.

Private Sub txtQuantity_1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim Message, Title, Default, MyValue
Message = "Enter the next quantity" ' Set prompt.
Title = "Quantity" ' Set title.
Default = "" ' Set default.
' Display message, title, and default value.
Dim Msg, Style, Ttle, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbDefaultButton2 ' Define buttons.

Response = MsgBox(Msg, Style, Ttle, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Set Mycmd = Me.Controls.Add("Forms.TextBox.1", name, True)
MyValue = InputBox(Message, Title, Default)
Mycmd = MyValue

Else ' User chose No.
MyString = "No" ' Perform some action.
End If
End Sub




dan dungan

how to store user responses
 
Thanks,

It works as you say. Maybe I can adapt it.

Thanks again.

Dan


All times are GMT +1. The time now is 10:51 AM.

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