Dynamically Create Userform Through Class Modules?
Feb 15, 2013
I have a problem with a dynamic userform that I need to create.
I need a userform in which the number of controls are determined by the some values in the worksheet. The users of the workbook must be able to add new controls to the form, so I do not know the number of controls in advance. I therefore can not create the userform through the design module but must create it through code instead.
I need a userform with a number of comboboxes and a commandbutton, which when clicked sends the content of the comboboxes to the first empty row in a worksheet.
My problem is that I can't assign any commands to the comboboxes (which are created at runtime), nor can I use the values of the comboboxes in any commands assigned to other controls in the userform (e.g. the commandbutton).
I have read as far that I probably need some form of class module to create the controls at runtime, but since I am relatively new at VBA, I'm having trouble getting the class module to work in connection with the userform.
View 2 Replies
ADVERTISEMENT
May 12, 2014
I wrote some macros that allow me to check info when i input employee number and dates on a worksheet. There are three buttons in my macro which are "Prepare" (do some preparation for the origional data in order to perform check ups later on), "Clear" (clear info in order to perform next check up), "Check" ( Check the info that i need). I already finished the code for all three buttons and they are all functioning.
My question is how to create a userform that allows me to do the same thing as a macro. for example, on the userform window, there should also be three command buttons ("Prepare","Clear","Check") and also there should be three textbox labeled as "Employee Number","DateFrom","Date To" and the value of these textboxes are just the same as the input value for the macro( ie. In the macro, these three inputs are located at cells "B2","C2","D2")
View 3 Replies
View Related
Jul 23, 2009
i've reached a point where i would like to learn more about class modules but i have no resources. When i create a Class object can i visually see it? i want to know as i'm looking to use them within userforms if possible
View 4 Replies
View Related
Nov 29, 2007
I am working on a dynamically produced userform but the dynamically created Cancel and OK buttons don't work. I have been able to get round it by adding the buttons to the top of the form (non- dynamic) but I'd really like to be able to create them dynamically based on variable for other parts of the project. How can I produce dynamic command buttons that actually work?
Here's my code but I'd be happy with generic code I could use.
Private Sub UserForm_Activate()
' Define variables
Dim LabelV As MSForms.Label
Dim CheckboxV As MSForms.Checkbox
Dim rngFields As Excel.Range
Dim field As Excel.Range
Dim lngNextTop As Long
Dim lngTitleBarHeight As Long
Dim ColumnNum As Integer
' Set constants
' Choose height and width of Label box
Const cTextBoxHeight As Long = 12..............
View 9 Replies
View Related
Oct 14, 2008
I'm wondering about class modules and what they can be used for etc etc? i want to continue developing my VBA and feel that this area is the next step?
View 2 Replies
View Related
Jul 8, 2009
I am working with a class module and some fields require specific inputs that another coder may not intuitively know. How can I create a list of acceptable conastants that will appear as a drop down when the user is coding with the custom object?
For example:
I am creating an Email Engine object that will handle all my emailing needs in code, because coding emails is such a pain. Then I can just create the blasted thing, import the class module where needed and never have to worry about it again. Some coworkers are interested in using the module for their projects when I am finished. I want to put an option for message flags in the object, but only certain colored flags are allowed. How can I get the VBE to show a little drop down with the acceptable flag constants when another user types
[Object Variable].MessageFlagColor = {drop down list of options}
I started with
Public Property Let MessageFlagColor(Value As Constants)
End Property
But that hasn't gotten me anywhere.
View 9 Replies
View Related
Apr 27, 2014
The following code dynamically creates a number of textboxes within a frame with a label right next to it. There are two classes.
[Code] ......
The two classes look like this:
[Code] .....
This works just fine to create the dynamic series of textboxes and corrosponding labels. I am having trouble with the reference between them. for example (within the class module):
[Code] .....
As shown, the reference to the corresponding lable from within the class doesn't work. How to reference the correct corresponding label.
View 13 Replies
View Related
Mar 4, 2009
I have a userform with a single blank multipage. At runtime additional pages are added, the number of pages depends on input from another userform. Six frames, containing labels, textboxes and comboboxes are then added to each page.
I need to be able to use the textbox and combobox change events of these dynamically created controls to perform lookups and calculations. Although I can name the controls at the time they are created, it is not feasible to write code specifically for each control (I can have over 1,600 text boxes distributed over 9 pages, for example).
Having searched for some time on how to achieve this I believe using a class module is the way to go. However, how to use a class module is just not sinking in I'm afraid.
HTML Private WithEvents mpTextBox As MSForms.TextBox
Private WithEvents mpComboBox As MSForms.ComboBox
Private Sub Class_Initialize()
Set mpTextBox = MSForms.TextBox
Set mpComboBox = MSForms.ComboBox
End Sub
Private Sub mpComboBox_Change()
MsgBox "ComboBox value has been changed."
End Sub...........................................
View 2 Replies
View Related
Jan 27, 2010
I would like to create some VBA that looks for sub's or modules and delete them.
View 9 Replies
View Related
Jan 13, 2008
I make a userform called Option and now i want to call some of the variables of the userform in a module. First i try to copy this variables in a cell with the next
ActiveSheet.Cells(2, 3) = Me.MediaP.Value
and it works. But now, i want to call to MediaP in a module. For do that I try to do this:
With Worksheets("Hoja2")
.Range("B1").Value = Option.MediaP.Value
but it doesn't work. I don't want to use public variables or copy/use the information of the cell(2,3), i only want to know how use the information on the textbox called MediaP in a module.
View 3 Replies
View Related
May 3, 2012
I have several non-modal userforms in my App, some of them have date-fields that require manual entry typing of dd/mm/yy etc (No single userform has more than one date-box in it, this I think may be pivotally useful)
Now the Userform 'Calendar' that is built on the class of the same (cCalendar) name, has the write value line 'ActiveCell.value = theCal.value'
I'm looking to change this to refer to the correct userform.Textbox value, depending on which form is open.
I would imagine I could simply have a global string, whose value is set (or re-set) whenever a Userform is initialized (some sort of 'ActiveUF.value = Me.Name), where I get lost is referring to the components by name, so as to have a case statement by where I go:
Code:
Private Sub theCal_AfterUpdate()
Select Case ActiveUF
Case "AddForm"
application.vbe.components("AddForm").controls("AddFormDatePicker").value = theCal.value
Case "EditForm"
'.... etc
end select
end sub
better way of doing this (instead of passing around the userform name as a variable) - or proper syntax for referring to controls outside of the 'active' userform (but an open userform nonetheless)?
Every time I have to do this particular thing with userforms, I completely forget how, and the object browser always leads me on an infinite loop of Application.vbe.activevbproject.vbcomponents.vbe.active....
PS - there may be one slight complication to the process - one of the forms, has a 2-tab page in it, each page having similar (but named differently) fields. So I may need to be able to throw in 'Activepage' or whatnot
View 5 Replies
View Related
Oct 15, 2008
I'm looking for some VB code that will enable me to dynamically create Textboxes for every value that I have in a range.
Example date in range B2:B5:
apple
banana
orange
pear
I would want the macro to create 4 Textboxes on the active worksheet, each one with the text contained in the range.
View 9 Replies
View Related
May 4, 2007
Is there a way to create objects dynamically? for example, I know that I need to many create objects of a class, but I don't know how many objects I need before hand. Does VB allow you to create objects on the fly? If so, how can it be done?
View 3 Replies
View Related
Jul 29, 2009
or it's text box/ labels depending upon learning of how many records the application is working with?
I remember some body here has said that you could either
1 - create many labels and text box and then once run the application hides the number of the ones not use or
2 - you could once run the application have visual basic create label and text of the right number associate with the number of records working with.
I have looked at both these option and have found nothing. So is this possible and show some examples if you have them.
View 9 Replies
View Related
Jan 21, 2009
See the attached example. I have data listed as shown, but need the chart to automatically update whenever a new sales figure is added to the next month. I know you have to use the OFFSET to create dynamic ranges but I can't get it to work horizontally, only if my data is laid out vertically.
View 2 Replies
View Related
Apr 5, 2007
Is it possible to dynamically add or remove controls on an Excel userform using VBA? Doing this before the userform is displayed would be great.
View 9 Replies
View Related
Dec 16, 2007
I am looking for a solution to dynamically create named ranges according to the contents of cells in a particular column. The following code works for 1 word names, but in many cases the title cell contains numerous words separated by spaces. Is there a way I can adapt this code so that it will name the ranges with the spaces removed? For example, where cell C2 contains the narrative 'Sales Ledger Control', I would want the range name 'SalesLedgerControl'.
Range("R2:Z2").Name = Range("C2")
The named ranges are referred to in numerous other worksheets, where selecting a particular narrative from a listbox creates a dependant drop-down in the adjacent cell (eg if Sales Ledger Control is selected, the dependant list contains names of customers). FYI, the data validation in the other worksheets ignores the spaces in the range names, ie: =INDIRECT(SUBSTITUTE(G2," ",""))
It would not take me long to name the ranges manually, but a macro is preferable because the narratives in the title cells will often change and the range names will obvioulsy also therefore change.
View 4 Replies
View Related
Dec 16, 2013
I am creating a class list from a list of all students and classes. Names of students are in column A, their class name is in column B. In another sheet I would like to show a list of names from one particular class, say "Y8/En1".
Using a filter on the original list isn't an option as I will need it to pull/show other things eventually.
View 7 Replies
View Related
Apr 2, 2013
I have a userform that has one combobox at the top created manually. When the userform is opened, the user select an option in the combobox (these options are taken from a range on 1 worksheet). From the selection of the combobox, I use the comboxbox's change event to create and display 5 columns of textboxes and 2 columns of command buttons on the userform.
The number of rows of textboxes created depend on the option selected from the combobox since each option links to a different range of cells. Each of the 5 textboxes in each are set to be ".enabled = False" and display text as per the cell values within a range on another worksheet. 2 Columns of command buttons are created at the end of each row of textboxes - 1 is enabled and the other is not.
The creation of the textboxes and command buttons works as required. However, I am having problems with setting click events for each command buttons. When the 1st column of Command buttons are created, I need the click events to be created and filled out with 2 actions:
1. Enable all textboxes in the same row as the command button
2. Enable the other command button in the same row.
Here is the code I have so far that creates the textboxes and command buttons.
Each of the 5 textboxes and 2 command buttons have a unique name so the 1st row will have textbox and command button names of cTxtA1, cTxtB1, cTxtC1, cTxtD1, cTxtE1, CmdAmend1 and CmdConfirm1. The 2nd row will have the same names but with 2 on the end and so on. The bold sections is the code for the creation of the command buttons that I want click events for.
Code:
Private Sub CboTeamSelect_Change()
Application.ScreenUpdating = False
If CboGroupSelect.Value = "" Then Exit Sub
Dim cTxtA As Control, cTxtB As Control, cTxtC As Control, cTxtD As Control, cTxtE As Control
Dim CmdAmend As Control, CmdConfirm As Control
Dim iNum As Integer
Dim TxtTop As Long
[code]....
View 2 Replies
View Related
Mar 24, 2014
As you can see in the attached file, I have a column of classes , a columns of related revenues and the total for each class. I have to create a column, next to these, where I can create the percentage with respect the sum of each class (as you can see by the formula). My problem is I am not able to say vba to find the totals and to create the percentage just with the revenues related to that total.
p.s: I have to work on excel2010.
View 3 Replies
View Related
May 16, 2014
if there was a way to automatically add each student to a class list as their information is inputted. What i mean is, after input Sally Student in the main enrollment list she would automatically go to the class list for the class she has chosen.
I have attached a sample workbook with my desired results. Basically what i want to do is make this easier for those in charge to get the class lists from the main list without having to copy and past all the time.
The class lists are in the tabs in the workbook.
View 5 Replies
View Related
Nov 25, 2008
I've created a class called CStock. It has 5 standard properties (with Get/Let methods) as explained in that article above. Nothing fancy here.
I also want to create a CPortfolio class that has 3 properties: pName, pNumberofPositions, and pHoldings. the first 2 are stardard, but the last one is different. I want it to somehow keep a collection of stocks.
View 10 Replies
View Related
May 24, 2006
I've created two modules, card and pack. Card has three variables (value, name, suit) and pack is made up of an array of 52 cards. Referencing it from a test module (NOT a class module) I expected to be able to use debug.print pack.card(32).suit to return the suit of the 32nd card. Instead I get an error message "Object or With variable not set". What am I doing wrong
Private p_strSuit As String
Private p_strName As String
Private p_iValue As Integer
Public Property Let Suit(strSuit As String)
p_strSuit = strSuit
End Property
Public Property Get Suit() As String
Suit = p_strSuit
End Property
Public Property Let Name(strName As String)
p_strName = strName
End Property......................................
View 7 Replies
View Related
Mar 28, 2013
i want to create one user form like shown in this picture below. right side 3 options need to input form the user and clicking on the button get option chain, it gets the data from www and fills all the columns frm expiry to optn int..
View 2 Replies
View Related
Jul 16, 2008
I have created an order form and what I am trying to do is:
I would like that when our customers open the order form they should get a page with our Terms and conditions (maybe as User form), which they have to accept it or not. If they accept it, they should get the message i.e. “welcome to ....." but if they don't accept it they should get the message i.e. “the order form will close in 5 seconds " (and it should close after 5 sec.).
View 9 Replies
View Related
Mar 3, 2014
I created the following worksheet when a user opens my workbook:
Project #Project DescProject LeaderStatus Date
1Project Desc 1Jones02/04/2014
2Project Desc 2Jones02/21/2014
5Project Desc 5Smith02/04/2014
[Code] ........
I now need to take the worksheet fields and place them in a userform which will have the following:
View command button which has the hyperlink attached to it followed by boxes with the Project Desc, Project Leader and Status Date.
View 2 Replies
View Related
Nov 6, 2009
Enclosed is a copy of a workbook in Excel 2003, in which I copied the VBA from a web site to see how that works. I am not a guru in Excel but always curious to see how things can be achieved to maybe enhance it in the future use. I have tried everything based on my knowledge but did not succeed.
View 5 Replies
View Related
Aug 15, 2007
I want to create a userform that has several parts to it.
1stly i want to copy information into the text boxes from a macro.
2ndly the number of text boxes could be infinate (in theory), i want 1 for each set of info
3rdly i want a little option tab box thingy for each box,
4thly the boxes and userform to adjust to fit the optimal size
View 9 Replies
View Related
Jun 18, 2009
I am trying to create a userform during the progression of my code. I found this is the MS help website but it doesn't work for me . .
Sub BuildMyForm()
Set MyNewForm = _
VBE.ActiveVBProject.VBComponents.Add(ComponentType:=vbext_ct_MSForm)
End Sub
View 9 Replies
View Related
May 18, 2006
I am trying to create some controls in a userform on the fly based on the data in a sheet. The part of my code is the following:
summaryForm.Controls.Add bstrProgID:="forms.label.1", Name:="LAWts", Visible:=True
With summaryForm.Controls("LAWts")
.Top = 120
.Left = 20
.Height = 18
.Width = 300
.Caption = "Weights: "
End With
Question I is that how can I connet this textbox to a click event or just to a procedure when it is clicked? I tried to use OnAction but it does not work for textbox in a userform. Question II is that how can I find the all properties of a textbox or any other controls? Is there a manuel or reference available on the internet?
View 3 Replies
View Related