Create Userform on the Fly?

PA HS Teacher

Well-known Member
Joined
Jul 17, 2004
Messages
2,838
Is it possible to create a userform on the fly?

I know how to create controls on the fly.
e.g.
Set ctl = MyForm.Controls.Add("forms.CommandButton.1")

But what if I wanted to create MyForm on the fly?
 
Hi PaHs. Yes, Yes, and Yes... I'll delve into this with you later today. In the mean time, if you have the time, please describe what you need these ten forms to accomplish in a bit more detail. Your "highest" object can return these forms as properties or you can initiate instances directly. You can create as many as you'd like.

"I don't understand why your code does not have its own class module, and I"m not sure how to create multiple instances."

That's just example code placed in a sheet class to accommodate the WithEvents requirements. VBA lacks any ability to really utilize inheritance and polymorphism. If you will have ten forms in your project, create a template that contains the properties that are common to most or all of your forms. Create a private custom class module that returns intances of this form. Within, you could add any relevant events, properties, ect... The alternative is to create a "code" template using Tom U's or JWalks methods. The method we are discussing is a better choice when dealing with multiple forms that have similiar interfaces. I'll post an example later.

If possible, post your workbook, or at least some of your code. If you wish, you can post your workbook by:

1. Zip up your Excel file. It must be in zip format.
2. Email it to (mrexcel at fuse dot net)
3. Make sure that “MrExcelPostFile” is in the subject (without the quotes)

You should get a reply shortly with a URL to copy and paste directly to the board.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Right_Click
Thank you for taking the time to look at this. I really appreciate it. Let me preface this by saying that you need only consider Goal i). However, I’ve tried to provide you with the full picture of what I am trying to do. I’ve followed your instructions and am waiting for a response from MrExcel@fuse.net. ( I was wondering how people were posting their zip files). I’ve tried to strip the file down to only what is essential and I’ve included descriptions of what the file does in comments and textboxes within the file itself.

I’ve also included my code below. My goals, explanation of what the forms should do is below the code.

Overall Purpose:
1. To Design a Lesson planning system for myself. (I am a high school teacher)
To maintain and manipulate a database of Sections. Each Section represents a type of piece to one of my lessons, (HW, Lesson Objectives, Lab Descriptions etc.)

2. To facilitate the quick writing and viewing of my lesson plans.

3. To facilitate the quick generation of reports related to my lesson plans.

For now I am concerned predominantly with Purpose # 1.


What I've done:
a) I’ve set up this database such that each section gets 1 sheet.
b) Each Sheet contains “Pieces” or records of an object of class clsPiece
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>
<SPAN style="color:#00007F">Public</SPAN> colInstances <SPAN style="color:#00007F">As</SPAN> Collection

<SPAN style="color:#00007F">Public</SPAN> IDRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> TxtRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> NumUsesRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> RnkUsesRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> LastUseRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> OrderRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> RetiredRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> LastTermRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> CreatedRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> LastModifiedRng <SPAN style="color:#00007F">As</SPAN> Range

<SPAN style="color:#00007F">Public</SPAN> TxtLabel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> clsCtlTxtLbl
<SPAN style="color:#00007F">Public</SPAN> IDCommand <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> clsCtlIDCmd
</FONT>

c) Each Piece Contains information about that Piece (particular HW, Objective etc.). It also contains information about specific uses of that Piece, with the relevant information for each specific use stored in a the collection listed above called colInstances, which contains objects of class clsInstanceSpecific

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>
<SPAN style="color:#00007F">Public</SPAN> DayRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> SectionRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> TxtRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> DaySectionRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> TermRng <SPAN style="color:#00007F">As</SPAN> Range
<SPAN style="color:#00007F">Public</SPAN> OrderRng <SPAN style="color:#00007F">As</SPAN> Range</FONT>
d) I’ve had success creating the TxtLabel, and IDCommand properties (controls) on an existing userform.

Problem:
I would like be able to create a clsSection Object
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>
<SPAN style="color:#00007F">Public</SPAN> Pieces <SPAN style="color:#00007F">As</SPAN> Collection
<SPAN style="color:#00007F">Public</SPAN> PieceFrm <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> PieceTemplateForm
<SPAN style="color:#00007F">Public</SPAN> ID <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">Public</SPAN> Title <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">Public</SPAN> Line <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
<SPAN style="color:#00007F">Public</SPAN> DisplayHeader <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>
<SPAN style="color:#00007F">Public</SPAN> CenterHeader <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>
<SPAN style="color:#00007F">Public</SPAN> Exclude <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN></FONT>
for each section, based on a template form called PieceTemplateForm, and then collect all of the clsSection objects into a collection called AllSections.

The clsFrmPiece was my attempt at adapting your code
<font face=Courier New>  <SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">WithEvents</SPAN> uf <SPAN style="color:#00007F">As</SPAN> UserForm
  <SPAN style="color:#00007F">Private</SPAN> mtf <SPAN style="color:#00007F">As</SPAN> PieceTemplateForm
  
  <SPAN style="color:#00007F">Sub</SPAN> MyInitialize()
       <SPAN style="color:#00007F">Set</SPAN> mtf = <SPAN style="color:#00007F">New</SPAN> PieceTemplateForm
       <SPAN style="color:#00007F">Dim</SPAN> l <SPAN style="color:#00007F">As</SPAN> MSForms.Label
      
       mtf.Caption = "Instance of MyTemplateForm"
       <SPAN style="color:#00007F">Set</SPAN> l = mtf.Controls.Add("Forms.Label.1", "Description", <SPAN style="color:#00007F">True</SPAN>)
           l.Caption = "This is a simple blank form. I can do whatever " & _
                      "I wish via code... Click the form!"
           l.AutoSize = <SPAN style="color:#00007F">True</SPAN>
     <SPAN style="color:#007F00">'  mtf.Show</SPAN>
       <SPAN style="color:#00007F">Set</SPAN> uf = mtf
       Unload mtf
       <SPAN style="color:#00007F">Set</SPAN> mtf = <SPAN style="color:#00007F">Nothing</SPAN>
       <SPAN style="color:#00007F">Set</SPAN> uf = <SPAN style="color:#00007F">Nothing</SPAN>
  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
  
  <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> uf_MouseDown(<SPAN style="color:#00007F">ByVal</SPAN> Button <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> Shift <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> X <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> Y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>)
       <SPAN style="color:#00007F">With</SPAN> mtf.Controls("Description")
           .Left = X
           .Top = Y
       <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
  
  
  <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> uf_MouseMove(<SPAN style="color:#00007F">ByVal</SPAN> Button <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> Shift <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> X <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>, <SPAN style="color:#00007F">ByVal</SPAN> Y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Single</SPAN>)
       mtf.Caption = X & ", " & Y
  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

I also have a Text Label Object clsCtlTxtLbl
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>
<SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">WithEvents</SPAN> TxtLabelGrp <SPAN style="color:#00007F">As</SPAN> MSForms.Label
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> TxtLabelGrp_Click()
MsgBox "clicked me "
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
And an ID Command Button Object clsCtlIDCommand
<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>
<SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">WithEvents</SPAN> IDCommandGrp <SPAN style="color:#00007F">As</SPAN> MSForms.CommandButton
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> IDCommandGrp_Click()
<SPAN style="color:#00007F">Dim</SPAN> sID <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
sID = IDCommandGrp.Caption
EditRecForm.Show
EditRecForm.IDLbl.Caption = sID
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

My Routine: Here is my routine for setting everything up. It’s in a regular module.

<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> fn <SPAN style="color:#00007F">As</SPAN> WorksheetFunction
<SPAN style="color:#00007F">Sub</SPAN> EstablishSections()
<SPAN style="color:#00007F">Dim</SPAN> TempFrm(1 <SPAN style="color:#00007F">To</SPAN> 5) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> PieceTemplateForm <SPAN style="color:#007F00">' Array, only because I've not had success</SPAN>
                                             <SPAN style="color:#007F00">' creating multiple instances of TmpFrm otherwise</SPAN>

<SPAN style="color:#00007F">Dim</SPAN> AllSections <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> Collection           <SPAN style="color:#007F00">' Section Collection (Each record represents the Info</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> recSection <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> clsSection            <SPAN style="color:#007F00">' on one Sheet, P1, P2 etc.</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> colPieces <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> Collection             <SPAN style="color:#007F00">' Collection of records within AllSections/</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> recPiece <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> clsPiece
<SPAN style="color:#00007F">Dim</SPAN> ColSpecificInstances <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> Collection  <SPAN style="color:#007F00">' Year Specific Instances, See G21 of Sheet P1 for an Expl.</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> recInstance <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> clsInstanceSpecific

<SPAN style="color:#00007F">Dim</SPAN> LastRow, LastCol, iFirstRow, iFirstCol, SecCnt, PieceCnt, InstCnt <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> PiecesRng <SPAN style="color:#00007F">As</SPAN> Range                      <SPAN style="color:#007F00">' Designates the cells on SectionWs sheet corresponding</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> SectionWs, SettingsWs <SPAN style="color:#00007F">As</SPAN> Worksheet      <SPAN style="color:#007F00">' to the pieces for a particular section</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> sSectionName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> ctl <SPAN style="color:#00007F">As</SPAN> Control
<SPAN style="color:#00007F">Dim</SPAN> IDWidth, iLeft, iTop, iHSpace, iVSpace, iMinHeight, iTxtWidth <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> iMinFormWidth, iMinFormHeight, i, j <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> PieceFrm <SPAN style="color:#00007F">As</SPAN> User<SPAN style="color:#00007F">For</SPAN>m
<SPAN style="color:#00007F">Set</SPAN> fn = Application.WorksheetFunction
<SPAN style="color:#00007F">Set</SPAN> SettingsWs = ThisWorkbook.Worksheets("Settings") <SPAN style="color:#007F00">' Will reside in a separate WS later. See Settings WS for expl.</SPAN>
iFirstRow = 21  <SPAN style="color:#007F00">' The Year specific Instances, recPiece.colInstances start at this row</SPAN>
iFirstCol = 7   <SPAN style="color:#007F00">' First recPiece starts at this column of SectionWs worksheet</SPAN>

<SPAN style="color:#00007F">For</SPAN> SecCnt = 2 <SPAN style="color:#00007F">To</SPAN> SettingsWs.Range("C65535").End(xlUp).Row <SPAN style="color:#007F00">' Loop through each "Section" as listed on on SettingsWs</SPAN>

  sSectionName = SettingsWs.Cells(SecCnt, 3).Value
  <SPAN style="color:#00007F">Set</SPAN> SectionWs = Worksheets(sSectionName)


  LastRow = SectionWs.Range("A65535").End(xlUp).Row
  LastCol = SectionWs.Range("IV1").End(xlToLeft).Column
  
  <SPAN style="color:#00007F">Set</SPAN> PiecesRng = SectionWs.Range(SectionWs.Cells(1, 7), SectionWs.Cells(LastRow, LastCol))
<SPAN style="color:#007F00">' *****************************************************************************</SPAN>
<SPAN style="color:#007F00">' *****  Pull Pieces Information into Collection of clsPiece Objects ******</SPAN>
<SPAN style="color:#00007F">For</SPAN> PieceCnt = 1 <SPAN style="color:#00007F">To</SPAN> PiecesRng.Columns.Count
  <SPAN style="color:#00007F">With</SPAN> recPiece
    <SPAN style="color:#00007F">Set</SPAN> .IDRng = PiecesRng(1, PieceCnt)
    <SPAN style="color:#00007F">Set</SPAN> .TxtRng = PiecesRng(2, PieceCnt)
    <SPAN style="color:#00007F">Set</SPAN> .NumUsesRng = PiecesRng(3, PieceCnt)
    <SPAN style="color:#00007F">Set</SPAN> .RnkUsesRng = PiecesRng(4, PieceCnt)
    <SPAN style="color:#00007F">Set</SPAN> .LastUseRng = PiecesRng(5, PieceCnt)
    <SPAN style="color:#00007F">Set</SPAN> .OrderRng = PiecesRng(6, PieceCnt)
    <SPAN style="color:#00007F">Set</SPAN> .RetiredRng = PiecesRng(7, PieceCnt)
  <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
  
<SPAN style="color:#007F00">' Collect The Specific Instances for this Piece (See G21 of P1 sheet for an explanation)</SPAN>
  For InstCnt = iFirstRow <SPAN style="color:#00007F">To</SPAN> PiecesRng.Rows.Count
    <SPAN style="color:#00007F">With</SPAN> recInstance
      <SPAN style="color:#00007F">Set</SPAN> .DayRng = PiecesRng(InstCnt, 1).Offset(0, -6)
      <SPAN style="color:#00007F">Set</SPAN> .SectionRng = PiecesRng(InstCnt, 1).Offset(0, -5)
      <SPAN style="color:#00007F">Set</SPAN> .DaySectionRng = PiecesRng(InstCnt, 1).Offset(0, -4)
      <SPAN style="color:#00007F">Set</SPAN> .TermRng = PiecesRng(InstCnt, 1).Offset(0, -3)
      <SPAN style="color:#00007F">Set</SPAN> .OrderRng = PiecesRng(InstCnt, 1).Offset(0, -2)
      .DaySectionRng.Value = Format(.DayRng.Value, "mmmm dd yyyy") & ":" & .SectionRng.Value
      <SPAN style="color:#00007F">Set</SPAN> .TxtRng = PiecesRng(InstCnt, PieceCnt)
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
      ColSpecificInstances.Add recInstance, recInstance.DaySectionRng.Value
      <SPAN style="color:#00007F">Set</SPAN> recInstance = <SPAN style="color:#00007F">Nothing</SPAN>
  <SPAN style="color:#00007F">Next</SPAN> InstCnt
  
  <SPAN style="color:#00007F">Set</SPAN> recPiece.col<SPAN style="color:#00007F">In</SPAN>stances = ColSpecificInstances
  colPieces.Add recPiece, recPiece.IDRng.Value
  <SPAN style="color:#00007F">Set</SPAN> ColSpecificInstances = <SPAN style="color:#00007F">Nothing</SPAN>
  <SPAN style="color:#00007F">Set</SPAN> recPiece = <SPAN style="color:#00007F">Nothing</SPAN>
  <SPAN style="color:#00007F">Set</SPAN> recInstance = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">Next</SPAN> PieceCnt



<SPAN style="color:#007F00">'*****************  Set Up Piece Form *******************</SPAN>
iLeft = 10
IDWidth = 25
iTxtWidth = 378
iHSpace = 10
iVSpace = 10
iMinHeight = 10
iMinFormWidth = 500
iMin<SPAN style="color:#00007F">For</SPAN>mHeight = 300
iTop = iVSpace

<SPAN style="color:#00007F">Set</SPAN> recSection.Pieces = colPieces
<SPAN style="color:#00007F">Set</SPAN> recSection.PieceFrm = TempFrm(SecCnt)
<SPAN style="color:#00007F">Set</SPAN> colPieces = <SPAN style="color:#00007F">Nothing</SPAN>
  recSection.PieceFrm.Caption = sSectionName
  recSection.PieceFrm.Width = iTxtWidth
  recSection.PieceFrm.Height = fn.Max(ActiveWindow.Height, iMinFormHeight)
  recSection.PieceFrm.ScrollBars = fmScrollBarsVertical

For <SPAN style="color:#00007F">Each</SPAN> recPiece In recSection.Pieces
<SPAN style="color:#00007F">With</SPAN> recPiece
                   <SPAN style="color:#007F00">' Piece ID Label</SPAN>
  <SPAN style="color:#00007F">Set</SPAN> recPiece.IDCommand.IDCommandGrp = recSection.PieceFrm.Controls.Add("forms.CommandButton.1")
  .IDCommand.IDCommandGrp.Top = iTop
  .IDCommand.IDCommandGrp.Left = iLeft
  .IDCommand.IDCommandGrp.Height = iMinHeight
  .IDCommand.IDCommandGrp.Width = IDWidth
  .IDCommand.IDCommandGrp.Caption = .IDRng.Value
  
                     <SPAN style="color:#007F00">' Piece Text Label</SPAN>
  <SPAN style="color:#00007F">Set</SPAN> recPiece.TxtLabel.TxtLabelGrp = recSection.PieceFrm.Controls.Add("forms.Label.1")
  .TxtLabel.TxtLabelGrp.Top = iTop
  .TxtLabel.TxtLabelGrp.Left = iLeft + IDWidth + iHSpace
  .TxtLabel.TxtLabelGrp.Height = iMinHeight
  .TxtLabel.TxtLabelGrp.Width = recSection.PieceFrm.Width - 3 * iHSpace - IDWidth
  .TxtLabel.TxtLabelGrp.Caption = .TxtRng.Value
  .TxtLabel.TxtLabelGrp.AutoSize = <SPAN style="color:#00007F">True</SPAN>
  
   iTop = iTop + .TxtLabel.TxtLabelGrp.Height + iVSpace
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
<SPAN style="color:#00007F">Next</SPAN> recPiece

recSection.PieceFrm.ScrollHeight = iTop + 20
recSection.PieceFrm.Show
recSection.ID = SettingsWs.Cells(SecCnt, 3).Value
recSection.Title = SettingsWs.Cells(SecCnt, 4).Value
recSection.Line = SettingsWs.Cells(SecCnt, 5).Value
recSection.DisplayHeader = SettingsWs.Cells(SecCnt, 6).Value
recSection.CenterHeader = SettingsWs.Cells(SecCnt, 7).Value
recSection.Exclude = SettingsWs.Cells(SecCnt, 8).Value

MsgBox (recSection.Pieces.Count & " records and " & Chr(10) & _
        recSection.Pieces(1).colInstances.Count & " 'Yr Specific Instances' in " & _
        recSection.Pieces(1).IDRng.Value & Chr(10) & " from sheet " & _
        recSection.ID & ", which is the " & recSection.Title & " Section.")

AllSections.Add recSection, recSection.ID
MsgBox AllSections(1).PieceFrm.Caption
<SPAN style="color:#00007F">Set</SPAN> recPiece = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">Set</SPAN> recSection = <SPAN style="color:#00007F">Nothing</SPAN>

<SPAN style="color:#00007F">Next</SPAN> SecCnt

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>


Goals: (In order of decreasing importance to me at the moment)
i) A userform for each section is always loaded and accessible in the background.
ii) Clicking on the Command Button on the Section Form allows an EditRecord form to load and show, allowing the user to edit information about the particular piece corresponding to that command button (IDCommand of clsPiece)
iii) When the EditRecord form is closed, I would like all changes to be reflected in clsPiece, and hence the appropriate cells on the Section Worksheet.
iv) Allow me to manipulated pieces on the PieceFrm (e.g. move them up or down, reorder them, change the date for specific uses, only show pieces for a particular use etc.)

Future Goals:
v) A Later Goal Display Forms
I. Daily Lesson Plan (Display all pieces for a particular day and section)
II. Weekly Overview (Brief representation of the Lesson Plans for the Week)
III. Month Overview (Brief representation of the Lesson Plans for the Year)
IV. Displays by Section (e.g. List all homeworks for a unit)

Goals in a Land Far Far Away:
vi) Tools for comparing Lessons for year to year.
vii) tracking of student data such as attendance, tardiness, parent contact, discipline
vii) creating an excel menu structure for selecting classes, sections, semester, and
accessing various features.
 
Upvote 0
Tom,
Thank you for sharing your spreadsheet. It is very didactic, but I am trying to leave the VBE locked. As always, thank you for the help. I have saved this file away for another project, another day.

~ Dan
 
Upvote 0
PA HS Teacher Frm Obj.zip

Sorry Dan. I have some code in Outlook that was supposed to post your file but it errored out. Just got home from work. Anyway, Dan's file is above. I'll take a look at it later...
 
Upvote 0
BTW. I am not affiliated with Mr Excel. I only post here. The email address is just for my own organizational reference...
 
Upvote 0
Tom,

Take your time, It's a personal project for me, so I don't suffer from any pressure's or deadline's from above. It's the largest of my personal pet projects for the summer. I was hoping to finish Goal i) over the next week or two. I have numerous other projects Excel and otherwise to keep me busy. Thanks again for having a look at it, and for your creativity in providing a means for posting files on this board.

~ Dan

[edit] I just found this site today which lets you store and share up to
1 GB of files for free! Here's a link to an unzipped version of my file
http://www.box.net/public/b96rioc39f
 
Upvote 0
Hi Dan.

I have looked at your file and will need to take several more glances before I can get the big picture. :)

Just wanted you to know that I have not forgotten your post.

If anybody else wants to take a look and offer some suggestions...

PA HS Teacher Frm Obj.zip
 
Upvote 0
Dan

Why not just use Access or another database application?
 
Upvote 0
Norie,
Access would be great for this task, but most school computers do not have Access, and I want this file to be functional on any PC. Virtually all school computers have Excel, maybe 10% has access. (I also to not have Access at home.)

Tom, (and anyone else interested)
Please do not feel obligated to digest all of my previous post. This project is a culmination of several years of thinking, and I don't won't to force it on anyone. Let me distill my question into a simple problem that represents my question.

Objective:
Create Multiple Instances of a variable/ class called clsMyObject, based on information contained in the sheet shown below. MyObject contains a userform, controls, and other "regular" variables.<font face=Courier New>uf<SPAN style="color:#00007F">As</SPAN> UserForm
MyProperty1<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">String</SPAN>
MyProperty2<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Integer</SPAN>
MyTextBoxes<SPAN style="color:#00007F">As</SPAN> Collection</FONT>
Book1
ABCDEFGH
1MyObjectMyFormMyProperty1 as StringMyProperty2 as IntegerMyTextBox1MyTextBox2MyTextBox3As many as 100 Textboxes
2MyObject1MyForm1I am Form 11xxxx
3MyObject2MyForm2I am Form 22xxx
4MyObject3MyForm3I am Form 33xx
5MyObject4MyForm4I am Form 44x
Sheet1


I will not know until runtime how many instances to create. If I was to run the desired code on the example sheet below, 4 instances of MyObject would be created.

Instance 1 would include a userform with 4 textboxes, each containing the letter x.

Instance 2 would contain a form with 3 textboxes.

Instance 3 would contain a form with 2 textboxes.

Instance 4 would contain a form with 1 textbox.

The userforms should be loaded simultaneously in the background.

The template form for uf could be a blank form. The only reason for a template form at all is my desire to create the forms w/out accessing the VBE via code.

Thank you for entertaining my problem.
 
Upvote 0
Dan

Thought that might be your response, just wanted to put forward another idea.:)

I'll download the attachments, and have a thorough read of the thread when I have more time.
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,418
Members
449,449
Latest member
Quiet_Nectarine_

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