Create Control Problem

dreamdelerium

Registered User.
Local time
Today, 15:04
Joined
Aug 24, 2007
Messages
88
hey everyone, im having some problems with CreateControl method. i have a function that is called when a button is clicked. what i want this function to do is create a text control on a tabcontrol page. it will be called from a button press event (the button is found on the same form as the tab control) my code is as follows:


Code:
Code:
Function MakeControl()
on error goto errorhandler

Dim ctl As Control
DoCmd.OpenForm "frmLayout", acDesign
   Set ctl = CreateControl("frmLayout", acTextBox, acDetail, "Page002")
   ctl.Top = 0.5 * 1440
   DoCmd.openfrom "frmLayout,acNormal

errorhandler:
MsgBox (Err.Description)

End Function
if i run this code directly from the module (click the function in the module and press the run button), it works fine. but if i try to call it from anywhere else (another function, sub, event) i get the following error: "MyApplication cant add,rename, or delete the control(s) you requested"

whats going on?

oh, yeah. this function will be called from an access form
 
first thing I would do is check the rest of the code that's in the function or sub from which you are calling. You may a routine in process within the source function that is conflicting, although I don't know what it could be at the moment.

And, another thing too....if you're trying to call this function from say, a button, you will get that error because you have to add controls to forms when in design view, but you can't run an OnClick event of a button in design view because you can only click on a button in form view! ;)
 
Last edited:
The BIG Question would be why are you trying to add controls dynamically? What is the purpose? There may be other ways to accomplish what you need, or you may need to think about this in a slightly different way.
 
That's my first thing that comes to my mind, Bob, every time I read about someone trying to do this!
 
It worked for me except at the end

DoCmd.openfrom "frmLayout,acNormal . That occurred with running direct and compile.

I also ran the function with RunCode in a macro, but minus the above line

Also placed the macro on a label on another form. Running the macro from that form opened the nominated form in Design view and had the control added. From then it was close/save. There was also an Access OK box that opened.
 
the million dollar answere

im currently working for a research group. every few months they need to create questionnaires (which they will use spss to do data analysis on so it has to be in access so they can export to spss). right now they have to pay someone to create the new questionnaires every month (im working in Africa, so talent isnt easy to come by so its expensive). im trying to create a wizard that will allow anyone who knows how to use a computer to create these questioners. the outline follows the following description: each question are has an unspecified number of pages (or tabs), each page with a max of 10 questions (labels and combo box's to select the answer). as each questionnaire would be different from month to month there is no way to know how many pages or questions on each page. so, the way i envision this is the application will start with one tab (with 10 questions on it). by clicking a button on the page, you can add a new page. by clicking another button you can create a new question on a page. if you guys can think of a better way to do this, please let me know.

thanks for your help
 

Users who are viewing this thread

Back
Top Bottom