Creating a form on the fly..Label position not sticking

Kristin in CT

New Member
Joined
Sep 5, 2006
Messages
7
I have this code working fine when i run it with the debugger on or if i add a prompt after the creation of the label. I've tried a few different pieces of code and have see other code snippets that appear to do exactly what i'm doing but in some cases my TOP and left properties do not stick. Any ideas would be greatly appreciated. Here's a sample of what the code looks like...

for i = 1 to 24

Set NewLabel = TempForm.Designer.Controls.Add("forms.label.1")
extraLines = extraLines * 12

With NewLabel
.WordWrap = False
If extraLines > 0 Then .WordWrap = True
.Caption = i & ". " & SurveyQsht.Cells(2, i + 1)
.Height = 24 + extraLines
.Width = lblLen
.AutoSize = True
.Font.Name = "Verdana"
.Font.size = 10
.ForeColor = vbBlue
.Top = ctrlTopPos
.Left = 26
' MsgBox NewLabel.Top
End With
ctrlTopPos = ctrlTopPos +26
next i
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I think the rule of thumb for me will be position & size before format.
I also noticed similar issues when the listbox was the last control...


With NewLstBox
' .ListStyle = fmListStyleOption 'top not set Properly
.Top = ctrlTopPos
.Left = 36
' .ListStyle = fmListStyleOption ' height is not set correctly
.Height = 32
' .ListStyle = fmListStyleOption ' width is not set correctly
.Width = optwidth
.ListStyle = fmListStyleOption ' all position & size set correctly
.Name = "Q_" & i
tName = "Q_" & i
.Font.Name = "verdana"
.Font.size = 10
.MultiSelect = fmMultiSelectMulti
.Width = optwidth
.Height = 32

Thanks for your help. Half the battle sometimes is setting aside the frustration and talking through the problem with someone. Thank you! :biggrin:
 
Upvote 0

Forum statistics

Threads
1,215,749
Messages
6,126,656
Members
449,326
Latest member
asp123

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