Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Run time error adding controls to form programatically

Hi,

I've got some VBA that programatically adds additional optionbox controls to
a userform (call this FRM_CHOOSE). The addition is actually driven by
another userform (call this FRM_UPDATE) which up til now only contained
optionbutton and commandbutton controls and everything has been working fine.


I've now added a combobox to FRM_UPDATE however now when the script gets to
the point of adding the new optionbox control to the other form it errors out
with "Run-time error '-2147319767 (80028029)': Invalid forward reference, or
reference to uncompiled type.".

The code I'm using is:

Dim my_form As Object
Set my_form = ThisWorkbook.VBProject.VBComponents("FRM_CHOOSE")
buttonnam = "opt_" & prog_sel
With my_form.codemodule
.insertlines 30, " Elseif FRM_CHOOSE.opt_" & prog_sel & "= true
then"
.insertlines 31, " rangechoice = """ & "all" & prog_sel & """"
.insertlines 32, " linechoice = """ & prog_sel & "lines"""
.insertlines 33, " progchoice = """ & prog_sel & "prog"""
.insertlines 34, " sheetchoice = """ & prog_sel & """"
End With

---***this is now the point at which the code crashes***---

Set my_new_opt = my_form.Designer.Controls.Add("Forms.OPTIONBUTTON. 1")
With my_new_opt
.Caption = prog_sel
.Top = ((my_form.Designer.Controls.Count - 6) * 18) - 12
.Left = 12
.Width = 63
.Name! = buttonnam
End With

This has previoulsy worked perfectly, the ONLY change was to add the
combobox to FRM_UPDATE which is itself unloaded before the code reaches this
point, having passed the "prog_sel" variable to the script. I don't
understand how this additional control could cause a subsequent error of this
nature - any advice?!

Many thanks,

Rob.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding date and time to cell programatically? Simon Lloyd[_1327_] Excel Programming 3 March 11th 10 03:52 PM
Adding "additional" controls programatically What-A-Tool Excel Programming 13 March 4th 07 05:06 AM
Adding controls to a form at runtime Todd Huttenstine Excel Programming 0 March 23rd 06 04:29 PM
Adding controls to each page in a multipage form michael fuller Excel Programming 5 January 13th 06 10:46 PM
excel.exe error when adding controls to userforms Brian Excel Programming 0 February 20th 04 11:55 PM


All times are GMT +1. The time now is 12:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"