how to store user responses

D

dan dungan

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
 
J

JLGWhiz

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top