By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,844 Members | 1,472 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,844 IT Pros & Developers. It's quick & easy.

How can we create an object (edit box, checkbox) at run time ??

P: 25

This is related to Code Behind AutoForm question that I've posted yesterdat but no one replies to that.

What i want a solution for is I need to have a flexible page1 whereas the field/objects (fields from a certain table that were added/created dynamically in a separate page2) could be created in the page1 at run time (using VB code). I'm using MS Access 2003 in Windows XP environment.

I've tried the Load funciton but it's not working as the object does not have an index property in MS Access.

Your comments/suggestions will be a big help.


Nov 4 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 2,653
Hello, Cindy.

You may use CreateControl() method.
Keep in mind that form where control is being created has to be opened in design view and be not the form where CreateControl() method is being executed.
Below is a simple example.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command0_Click()
  3.     Dim strName As String
  5.     strName = "Form2"
  6.     DoCmd.OpenForm strName, acDesign
  7.     CreateControl strName, acTextBox, acDetail, , , 100, 100, 2000, 250
  8.     DoCmd.OpenForm strName, acNormal, , , , acWindowNormal
  10. End Sub
As an alternative you may design form with a sufficient fixed number of controls and change their visibility as required.

Nov 4 '08 #2

P: 25
Thank you so much Fish... it is really a big help...
Nov 4 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.