0

I'm trying to add dynamic controls to different frames in a UserForm. I'm working on Outlook 2016.

I want them to be displayed by row of 3 in each frame I have for each user I have and then 3 others right below the first and so on. Example :

Frame1                   Frame2
Label1  Label2  Label3   Label1  Label2  Label3
-user1  -user1  -user1   -user1  -user1  -user1
-user2  -user2  -user2   -user2  -user2  -user2
...

What I get now is https://i.stack.imgur.com/4VBnw.jpg

With my example this would look like this :

Frame1
Label1              Label2              Label3
-lastUserOfTheList -lastUserOfTheList -lastUserOfTheList

Code :

At the time being, I'm able to create my controls but they all seem to overlap even though I'm setting their Left and Top properties.

I do set a new control with this :

Set opBtn = Me.Frame1.Controls.Add("Forms.OptionButton.1")

And then I set the properties by calling another sub which I give some arguments :

Call setControlProperties(userNumber, optionButtonCaption, opBtn, x)

This sub does contain :

With opBtn
    .Left = x * 36
    .Top = 18 + (userNumber * 18)
    .Caption = optionButtonCaption
    .Height = 36
    .Width = 48
    .ZOrder (0)
End With

x is an integer variable I use to increment the Left property so the controls don't overlap (but for now they do). userNumberis another integer variable that I use to increment the Top property. Each user has its own "Top value". OpBtn is a MSForms.Control variable.

I'm sure my frames are wide enough to host the dynamic controls.

Question : My question is the following : Does anyone know why theses controls overlap despite the fact I'm setting their .Top and .Left property to be different ?

PS : This is my first post here so I hope I did not forget anything.

Edit 1 : I put the code contained in setControlProperties right after the

Set opBtn = Me.Frame1.Controls.Add("Forms.OptionButton.1")

as suggested but it does still overlap. No further progress for now.

Edit 2 : I added the property GroupName to my opBtn control and now some controls are a bit exceeding from the overlap. I'm now sure it is an overlap but I still can't figure out why.

Edit 3 : I used the watch window along with f8(line by line) to observe the value of my opBtn.Left and opBtn.Top during the execution. Both are always correctly incremented. I also tried to modifiy every OptionButton object proprety but I always get the same result.

Edit 4 : I added a name and forced the control to be visible but this had no effect.

Set opBtn = Me.Frame1.Controls.Add("Forms.OptionButton.1", "dynamicButton" & x, True)
Jérémy Gamba
  • 70
  • 1
  • 10
  • Welcome to Stack Overflow! Perhaps a screen shot would help convey your question, including notes on the image as to your desired result (in more than one iteration of your loop). Or, something that could help you find the problem would be to **step through your code** to see which of your calculations is incorrect. **(More on that [here](https://stackoverflow.com/a/50189159/8112776).)** – ashleedawg May 11 '18 at 12:05
  • I can't add images as I'm new and don't have reputation. Here is a screenshot (https://imgur.com/a/FWtshTt), starting to read your link now. Thanks – Jérémy Gamba May 11 '18 at 12:11
  • Put your code where `setControlProperties` is called. – Maciej Los May 11 '18 at 12:37
  • @MaciejLos It does still overlap, no changing – Jérémy Gamba May 14 '18 at 07:00

1 Answers1

0

.Top = 18 + (userNumber * 18)

My userNumber variable was reset to 1 so the .top property always had the same value. Problem solved :)

Jérémy Gamba
  • 70
  • 1
  • 10