I have been gnashing this problem for a while now, and I cannot find the resolution. I previously posted a question re: building an form with code and got that all working great for several forms. But now I have run into a problem that I cannot figure out.
I have the following code:
It's driving me crazy because if I remove all the stops from the code, it just fails somewhere in the designated block. No error, it just exits the procedure without creating CommandButton.2.
There is some code prior to this block, and it works fine. All of the variables are declared, nothing is visually wrong that I can see. If I insert a break at the top of the "problem code block", it stops there and when I hit F8 it does fine until .InsertLines Line + 1, "Sub " & Btn.Name & "_Click()" and then tells me (understandably) that it can't enter break mode at this point.
If I put an error message in it says "error: -2147221005 Invalid Class String". I've googled this error and cannot find anything definitive to get me moving.
Can anyone see an issue?
I have the following code:
Code:
...
topPos = topPos + 24
Set Btn = objFrm.Designer.Controls.Add("Forms.CommandButton.1")
With Btn
.Caption = "Refresh View": .Height = 24: .Width = 78: .Left = 18: .Top = topPos:
End With
[COLOR=#FF0000]'GIVES ME AN ERROR SOMEWHERE IN THE CODE BLOCK BELOW[/COLOR]
With objFrm.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Sub " & Btn.Name & "_Click()"
.InsertLines Line + 2, " Dim cCont As Control"
.InsertLines Line + 3, " Dim lRow As Long"
.InsertLines Line + 4, " customFunctions.disable_Defaults"
.InsertLines Line + 5, " lRow = Sheets(""Headers"").Range(""A500"").end(xlUp).Row"
.InsertLines Line + 6, " For v = lRow To 2 Step -1"
.InsertLines Line + 7, " Select Case Me.Controls(""TextBox"" & v - 1)"
.InsertLines Line + 8, " Case Is <> """": Cells(v, 1) = Me.Controls(""TextBox"" & v - 1)"
.InsertLines Line + 9, " Case Else: Sheets(""Headers"").Range(""A"" & v).EntireRow.Delete"
.InsertLines Line + 10, " End Select"
.InsertLines Line + 11, " Next v"
.InsertLines Line + 12, " Unload Me"
.InsertLines Line + 13, " Call forms_SetUp.CreateFieldSetupForm"
.InsertLines Line + 14, " enable_Defaults"
.InsertLines Line + 15, "End Sub"
End With
[COLOR=#ff0000] 'GIVES ME AN ERROR SOMEWHERE IN THE CODE BLOCK ABOVE[/COLOR]
Set Btn = objFrm.Designer.Controls.Add("Forms.CommandButton.2")
With Btn
.Caption = "Save & Close": .Height = 24: .Width = 78: .Left = 114: .Top = topPos:
End With
' Code for the Click() event of the "Save & Close" button.
With objFrm.CodeModule
Line = .CountOfLines
.InsertLines Line + 1, "Sub " & Btn.Name & "_Click()"
.InsertLines Line + 2, " customFunctions.disable_Defaults"
.InsertLines Line + 3, " Thisworkbook.Save"
.InsertLines Line + 4, " Unload Me"
.InsertLines Line + 5, " Call forms_SetUp.DeleteAllForms"
.InsertLines Line + 6, " enable_Defaults"
.InsertLines Line + 7, "End Sub"
End With
End With
...
It's driving me crazy because if I remove all the stops from the code, it just fails somewhere in the designated block. No error, it just exits the procedure without creating CommandButton.2.
There is some code prior to this block, and it works fine. All of the variables are declared, nothing is visually wrong that I can see. If I insert a break at the top of the "problem code block", it stops there and when I hit F8 it does fine until .InsertLines Line + 1, "Sub " & Btn.Name & "_Click()" and then tells me (understandably) that it can't enter break mode at this point.
If I put an error message in it says "error: -2147221005 Invalid Class String". I've googled this error and cannot find anything definitive to get me moving.
Can anyone see an issue?