×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to create checkboxes on form-load?? (VERY URGENT)

how to create checkboxes on form-load?? (VERY URGENT)

how to create checkboxes on form-load?? (VERY URGENT)

(OP)
Hi there, it's me again... frag!

I have another problem!
I want to create some checkboxes (corresponding to a database field) on form-load for a form i have created in design-view.
Here is my code...

------------------------------------------------------------
Private Sub Form_Load()
 
 Dim ctlCheckbox As Control

 Set ctlCheckbox = CreateControl(Form.Name, acCheckBox,
                                 acDetail, "", "", 100, 100)

End Sub
------------------------------------------------------------

I keep getting this error-msg:
Run-time error '2147':
You must be in Design view to create or delete views.


What's wrong?

thanx.

frag

RE: how to create checkboxes on form-load?? (VERY URGENT)

(OP)
uuuups...

there is something i forgot:

i am using VBA for Access 97

:)

RE: how to create checkboxes on form-load?? (VERY URGENT)

The reason you're getting that message is because the CreateControl function can only add controls to a form that is in design view. It's really meant for creating your own wizards and things like that. Possibly what you could do is open the form intially in design view, add your controls and then open it normally. Try something along the lines of:


Public Sub MakeCtls()

    DoCmd.OpenForm "form1", acDesign, , , , acHidden
    CreateControl "form1", acTextBox, acDetail, , 15, 15, 15, 1500, 500
    DoCmd.OpenForm "form1"
    
End Sub

Durkin
alandurkin@bigpond.com

RE: how to create checkboxes on form-load?? (VERY URGENT)

(OP)
Hi Durkin!

Thanx for your reply.
I have checked out your piece of code... but this doesn't work either.

Run-time error '2174':
You can't switch to a diffrent view at this time.
Code was executing when you tried to switch views.
If you are debugging code, you must end the debugging operation before switching views.

I will just set my checkboxes to invisble and set them to visible at runtime when i need them. Ugly, but it works.

Thanx!

frag

patrick.metz@epost.de

RE: how to create checkboxes on form-load?? (VERY URGENT)

I'm unsure why you would need to create a control when the form opens.  Maybe the following would satisfy your requirement: creating the controls normally and setting their visible properties to false.  Then, when the form opens you set the visible property to true on whatever control you would need.  Another possibility would be to manage properties of a single control during the open event.  Hope one of these would help.

RE: how to create checkboxes on form-load?? (VERY URGENT)

(OP)
Hi scking!

Thanx for your reply.

1. visible/invisible
--------------------
   I already mentioned this in my last replay!


2. Why I need to create controls on formload
-------------------------------------------
   I get data from a database table. According to this data
   I have to set controls to visible/unvisible. Thought it
   would be nicer to have a dynamic form with dynamic
   controls (for saving place on the desktop).

But anyway... forget it. The app is finish and rolled out.

cya

frag

patrick.metz@epost.de

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close