0

I have a Userform that populates a series of Check boxes, Text boxes, and Combo boxes based on the content of a dictionary. The initialization of the Userform dynamically creates all the Control Objects and names them according to the type of control that they are and an index I have provided that corresponds to the dictionary object they were generated from. After the user interacts with the Userform, they click a button to process the results and the information in the controls are written to a class object for use in the next step of the program.

I need to be able to loop through the different controls objects, determine type of control that it is (ProgID), and check data/value within the object. I am having trouble finding an identifier that will allow me to differentiate between the various types of controls.

Currently, I am looping through the UserForm.Controls.Item list to have the objects returned to me. I cannot find any method of identifying the type of control from this object to determine what information needs to be pulled from it. Each type of control is written to a different property of the Class object.

Too Long; Didn't Read: I need a way to determine the ProgID (or equivalent identifier) of an object returned from the Userform.Controls.Item function.

Community
  • 1
  • 1
JustinCoplin
  • 169
  • 3
  • 16
  • What code have you tried and what error did it give you? Please include it in your question. – braX Dec 15 '17 at 13:59
  • 3
    `TypeName` will return the name of the controls type (for example, `Label` or `CommandButton`) – Vincent G Dec 15 '17 at 13:59
  • @braX This is not the sort of situation in which an error will be returned. The code can be posted, but the problem I am facing is that I do not know what I should be doing to get the information I am looking for, and thus the code is only half written. – JustinCoplin Dec 15 '17 at 14:01
  • @VincentG That is exactly the type of thing I am looking for. I'll write up a stub to test it out and see how it goes. – JustinCoplin Dec 15 '17 at 14:02
  • @VincentG Thanks, I successfully returned the information I was looking for. – JustinCoplin Dec 15 '17 at 14:07
  • 1
    I had the same issue, I ended up setting an ID code in the name of the control and then mapped it to a list so I knew what was what. I did use Type Name but Liked the control of knowing exactly what was what. – Keith Whatling Dec 15 '17 at 16:46
  • Since you're creating the controls at runtime from a set of data, the easiest approach would be to store a reference to each control (or set of controls) in that same dataset, and then use that when you need to process the user inputs. – Tim Williams Dec 15 '17 at 17:09
  • @TimWilliams Since my previous post, I've started storing them in a Dictionary within the Collection class the rest of the data uses. Its the First time I have done something like this with forms at runtime, so I am proceeding slowly and learning along the way. – JustinCoplin Dec 15 '17 at 17:37
  • 1
    Have a look [here](https://stackoverflow.com/questions/15457262/vba-msforms-vs-controls-whats-the-difference/15468230#15468230) to see limitations of `TypeName` and another possibility `TypeOf`. – Daniel Dušek Dec 16 '17 at 00:01

0 Answers0