My code below is giving an error on the line
Set VM = AP.VBProject.VBComponents("ViewManager").Designer.Controls
I have looked up many examples of working code and cannot figure out how mine is set up differently to cause an error.
The error is Run-time error '91': Object variable or With block variable not set
Thanks for any help.
Private Sub btnAdd_Click()
Dim View As String
Dim FField As String
Dim TField As String
View = cmbView.Value
FField = cmbFrmFld.Value
TField = cmbToFld.Value
'if it is the first add change one way, if after the first add change another
If ViewManager.Height = 116 Then
ViewManager.Height = ViewManager.Height + 64.5
ElseIf frmViews.Height > 116 Then
ViewManager.Height = ViewManager.Height + 30
End If
Dim AP As Project
Set AP = ActiveProject
Dim lbl As MSForms.Label
Dim VM As Object
Set VM = AP.VBProject.VBComponents("ViewManager").Designer.Controls
With VM
Set lbl = .Add("Forms.Label.1")
End With
With lbl
.Left = 6
.Top = ViewManager.Height - 32
.Width = 156
.Caption = View
End With
End Sub
I believe your problem is that you are using the VBIDE Forms Designer to add the control to you ViewManager form when it is loaded which is not possible. You can see this adding the following code to your module and adding a watch on the ‘VM’ VBComponent where the mouse stops (right click and add watch). You’ll see that the ‘Designer’ property is ‘Nothing’ whereas if you run the same code when the form is not loaded you’ll be able to access the Designer property and all it’s properties.
The simple workaround here is to add the control straight to the form at runtime and not use the VBIDE. For example: