Link to home
Start Free TrialLog in
Avatar of pipinana02
pipinana02

asked on

CreateControl using Access 2000

Hi.. i want to make a form in access 2000 which contains textboxes.. how can i create the textboxes using vba in runtime?


Private Sub Form_Load()

Dim newControl As Control
DoCmd.OpenForm "Form1", acDesign, , , , acHidden
Set newControl = CreateControl("Form1", acTextBox, , , , 100, 100, 1000, 1000)

DoCmd.RepaintObject acForm, "Form1"
DoCmd.Save acForm, "Form1"

End Sub


I can't find what mistake i made in that program.. Everytime i want to open Form1, there always be a Message Box:
Run-time error '2174':
You can't switch to a different view at this time.

Can somebody help me? Thanks :):)
Avatar of shanesuebsahakarn
shanesuebsahakarn
Flag of United Kingdom of Great Britain and Northern Ireland image

Which line do you get the error on ?
Avatar of pipinana02
pipinana02

ASKER

Hi.. hehehe.. sorry forget to mention.. i always get the error on line:

DoCmd.OpenForm "Form1", acDesign, , , , acHidden

Hehehe.. Hopefully u can help me.. :)
ASKER CERTIFIED SOLUTION
Avatar of shanesuebsahakarn
shanesuebsahakarn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi.. hehehe.. sorry forget to mention.. i always get the error on line:

DoCmd.OpenForm "Form1", acDesign, , , , acHidden

Hehehe.. Hopefully u can help me.. :)
Yes.. Form 1 is the form where the above code is in..

So, you mean i have to create another form that create Form1 is it? Can you give me example bcoz i'm a bit confused.. hehehe.. thankss :)
Basically, you just put the code you've already got above into say, a command button on another form. It will then be able to open Form1 in design view without a problem.
hehehe it works well.. thanks :)

but if i change to:
DoCmd.OpenForm "Form2", acDesign, , , , acWindowsNormal

the user will view Form2 in Design mode.. how to make the user only see it in Form View? Thanks again :)
I'm not sure I understand - can you not open it with acHidden as you did before ?

If you just want Form2 to open normally, simply use:
DoCmd.OpenForm "Form2"
oh.. okkk.. thanks soo much for helping me out :) hehehe i'm new to ms access.. so i'm not really familiar with it.. hehehe.. thankss :)