Newbie Userform questions: Userform to variables

Majawat

New Member
Joined
Jun 14, 2011
Messages
49
I appologize if this has been discussed elsewhere, I did a quick search on here and didn't come back with anything that suits my needs. Moreover, I've also searched google as well.

I just started using Userforms today. I've used Visual Basic before so I understand some about the theory about them, but am having trouble using them inside Excel 2010 to gather data.

I'm looking for a brief tutorial on using Userforms as a variable input, basically.

I have a collection (called BeerList) of a custom class called BeerType. The BeerType object (a variable called Beer in my sheet) has several varibles as one would expect: BeerName, Volume, Price, ABV, Style, etc.

After creating the UserForm (ManualAdd), I have the necessary TextBoxes/ComboBoxes to enter and a Submit and Done button.

My overal goal is to prompt for the information, fill in the variables, add to collection, ask for more data, and stop if asked.

Pseudocode:
Code:
Do 
     ManualAdd.show
     if ManualAdd.btnSubmit = clicked then
          beer.Name = ManualAdd.txtName
          beer.ABV = ManualAdd.txtABV
          beer.Volume = ManualAdd.Volume
          'other variables as needed
     end if

     ManualAdd.Controls.ClearContents

     BeerList.add beer
Loop Until ManualAdd.btnDone = Clicked

Please help, and thank you so much for your time! If I haven't provided enough information, please let me know and I will give more.
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
It looks like I may have found my answer after all, without adding global variables:

Code:
Private Sub manualAdd()
    Dim strbeerName, strContainer, strStyle As String
    Dim dblABV, dblPrice As Double
    Dim intVolume As Integer
    Dim boolFeatured, boolHouse As Boolean
 
    Do
        manualAdd.Show
        strbeerName = manualAdd.txtName
        'and the other variables

        MsgBox strbeerName 'to be replaced with the rest of the code
    Loop Until manualAdd.StopAdding
    
    Unload manualAdd
End Sub

(StopAdding is a gobal boolean inside the manualAdd userform)

Thank you very much bstier and royUK at ozgrid.com for your help!
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top