473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can Access Create Controls At Runtime?

50
I have a screen where I will need a LOT of checkboxes. The number I will need is based on how many records in the table - currently 194 but certain to grow larger in the future.

Can I create all these checkboxes at runtime? I know that in classic Visual Basic this was possible. But can it be done in Access? I have Access 2003.

I realize that creating controls at runtime slows down the app. This is not a high volume screen so if the user has to wait for a minute or more, it won't be a problem.

Any ideas or links?
Oct 15 '08 #1
6 7037
ADezii
8,834 Expert 8TB
Can I create all these checkboxes at runtime? I know that in classic Visual Basic this was possible. But can it be done in Access? I have Access 2003.
Yes and Yes! Reference the CreateControl() Method in the Help Files, and if you have any problem, let us know.
Oct 15 '08 #2
Krandor
50
Awesome. That was just what I needed.

Thanks.
Oct 15 '08 #3
Krandor
50
Yes and Yes! Reference the CreateControl() Method in the Help Files, and if you have any problem, let us know.
It worked but so far not exactly like I expected. What I wanted was for the user to open the screen and have all the controls created on the fly.

What I am getting is an error message that says Controls can only be created while in design mode. Here is the test code I was using.
Expand|Select|Wrap|Line Numbers
  1. Dim MyForm As Form, MyControl As Control
  2. 'Set MyForm = CreateForm()
  3. Set MyControl = CreateControl(Me.Name, 106)
  4. MyControl.Width = 2000
  5.  
Any ideas on how to make this work? And is there a way to assign a name to the control?
Oct 15 '08 #4
Krandor
50
What I am trying to do is this. As part of a software inventory system, I need to identify which pieces of software have been installed on a particular user's computer. That means we need to select the user from one list and then assign all the relevant software packages.

I thought to do this by dynamically creating one checkbox for each software package and then handling the updating of the relevant table via code.

If you have a simpler way to accomplish this I would love to hear it.
Oct 15 '08 #5
ADezii
8,834 Expert 8TB
What I am trying to do is this. As part of a software inventory system, I need to identify which pieces of software have been installed on a particular user's computer. That means we need to select the user from one list and then assign all the relevant software packages.

I thought to do this by dynamically creating one checkbox for each software package and then handling the updating of the relevant table via code.

If you have a simpler way to accomplish this I would love to hear it.
  1. Are you creating Controls on an existing Form, and if so what is its Name?
  2. If you are creating a New Form then adding Controls to the New Form, what are the Parameters?
  3. Are you selecting the User from a Combo Box, if so what is its Name? What is the relevant info for the Combo Box such as: Row Source, Bound Column, etc.
  4. How do you know which Software Packages are applicable to a specific User? List any Relationships, Table Names, and all Field Names and Data Types involved.
  5. You should get the idea by know, I simply do not have enough information to go on.
Oct 15 '08 #6
There is bug in MS Access that even if you follow the instructions from the official website of MS still you won't be able to "create" and "edit" controls at "run-time".
I found one way to go around this bug (witch is a combination of solutions I got from others).
Non working solution: Don't tray to define a variable to create the object:-

Sample 1:
Expand|Select|Wrap|Line Numbers
  1.         DoCmd.OpenForm "Form1", acDesign
  2.         Dim t as TextBox
  3.         set t = CreateControl("Form1", acTextBox)
  4.         t.FontName = "Arial"  'Any sample as test.   
  5.         .ForeColor = vbRead   'Any sample as test.   
  6.         .DefaultValue = 10    'Any sample as test.   
  7.         'etc...
  8.  
This way will give you error (by the way it is what you get from MS official site).

If you use the "With" it will work, but....
Sample 2:
Expand|Select|Wrap|Line Numbers
  1.         DoCmd.OpenForm "Form1", acDesign
  2.         With CreateControl("Form1", acTextBox)
  3.             .FontName = "Arial"  'Any sample as test.   
  4.             .ForeColor = vbRead  'Any sample as test.   
  5.             .DefaultValue = 10   'Any sample as test.   
  6.             'etc...     
  7.         End With
  8.  
This way Won't give you any error (bug free) But....
You won't be able to edit it later through the code; because we didn't use an object or variable to hold it or point to it (as in Sample 1).


My solution is: To use the name of the control to call it using "Controls()", and that is after useing "With" to create the control.:-
Sample 3:
Expand|Select|Wrap|Line Numbers
  1.         DoCmd.OpenForm "Form1", acDesign
  2.         Dim strName as string
  3.         With CreateControl("Form1", acTextBox)
  4.             .FontName = "Arial"  'Any sample as test.   
  5.             .ForeColor = vbRead     'Any sample as test.   
  6.             .DefaultValue = 10   'Any sample as test.   
  7.             ' etc...
  8.             strName = .Name   'Get the default name from the control (or you can give one).
  9.         End With
  10.         'And to be able to edit it later use the name you got in the previous lines.
  11.         Me.Controls(strName).FontName = "Times New Roman"    'Any sample as test.   
  12.         Me.Controls(strName).ForeColor = vbGreen            'Any sample as test.   
  13.         Me.Controls(strName).DefaultValue = 20                    'Any sample as test.   
  14.         ' etc...
  15.  
Sep 14 '15 #7

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

Similar topics

7
by: bettyann | last post by:
I am using Visual Basic 6.0. I have a TextBox control whose "Caption" I wish to access. When I look at the TextBox's structure via the "watch" window, its structure appears to look like the...
1
by: SAN CAZIANO | last post by:
how can i create a runtime table and define a new field to allow null value and set the rquired to true or false ???
2
by: Sean | last post by:
Hello all, I may just not be searching for the right thing, but I've been looking for a way to dynamically create controls (and name them) in my code so that I can create only the controls I...
0
by: Andrea | last post by:
Hallo, i create controls dynamically on my webproject. most of the controls i create in the oninit-event and all worked wunderfull, but in the event-handling, e.g. the click-event of a button, i...
1
by: bill yeager | last post by:
I did some more debugging and found the following: 1) I placed the following code in the button event just to see if I could cycle thru the datagrid control collection: <code> Dim strhello As...
3
by: Grey | last post by:
I know i can use placeholder control for dynamic create controls. but my requirement is i need to create multiple controls. when the user click the button, one textbox will be created. If user...
0
by: tommy | last post by:
hello everybody, i haved read a few articles about, how to create controls in asp.net dynamically! i have tested it -- all works fine.... but....now it comes--> HOW create controls...
2
by: Bernard Bourée | last post by:
I have created various controls by code and added them to a form. I need for some of them (TextBox) to modify the value. I use the folowing code to obtain the TextBox wich name is given by...
5
by: Anil Gupte | last post by:
How does one access dynamic controls by name (or whatever other means)? I have the following: Dim newbtnPick As New Button newbtnPick.Name = "SliceButton" & CurSliceNum newbtnPick.Location =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.