Instantiate Objects on FormLoad

jworthen

New member
Local time
Today, 10:52
Joined
Mar 26, 2007
Messages
4
I am trying to create a "dynamic" input form into access. Basically I have a list of vehicles held within a DB that mileage needs to be entered each month. Well what I want to do is be able to create the input boxes on the fly.

I am not new to coding, just have not worked with VB6 since like 2001 and trying to do some refreshing. I checked the DAO and it is installed correctly. I am working in Access 2003 on a Windows XP SP2 32bit system.

Here is the code I have:
Code:
Private Sub Form_Load()
Dim txtTest As New TextBox

' Error thrown here "ActiveX Component can't create object."
txtTest.Name = "txtTest"
txtTest.Value = "Testing"

End Sub

Anyhow the goal is ultimately be able to create the textboxes on the fly and display them on the form. If anyone can help me on how to instantiate the object or what I am doing wrong I would appreciate it. Thanks!
 
you can't create objects when the form is not in design view. Best way to accomplish dynamic creation of forms is to build the entire form (in design view, of course) then switch to normal view as opposed to adding objects to an existing form. Use the acSaveNo option on close.
 
Not really the answer I was hoping for, but at least I know now it is "impossible". Thanks for the reply, back to the drawing board.
 
Another option is to have a number of text boxes already created on the form and their visible property set to false and then display the ones you want at the time you need them.
 
Yea, that is actually the route I am going to take, create x amount of textboxes and than just hide the ones I won't use after I loop through my data.

It is a nasty hack but will work. I was just hoping that Access might of provided me with the proper way to go about it.
 
...I was just hoping that Access might of provided me with the proper way to go about it.
You ARE an optimist, aren't you? :D

One thing you need to remember is that when it comes to Microsoft and Access, it isn't always logical how to go about it. Microsoft seems to have some inconsistency on how somethings are done. It's hard sometimes to know how to deal with something because, for example, what will work in VB6 won't work in VBA, even though they are highly related.
 
You ARE an optimist, aren't you? :D

Well, I actually had hope for access at one point, now I lost all faith. I just wish my company would let me do this in PHP and it would be done and running with ease. Dang no-webserver rules.

Yea, when is Microsoft ever Logical about doing something. It is a shame that they did not just use VB6 or even VB .NET instead of going into the VBA. That is microsoft for ya, let's make everything difficult for everyone!
 
Yep, understand your frustration. I have a love/hate relationship with Access for similar reasons.
 
Can't you just have a query to select records with 0 or null in the mileage field and show them on a continuous form - then you don't need to try to add objects to forms dynamically
 
You can achieve what you are wanting to do using CreateControl but it would have to be triggered from another form.

I created a dynamic form based on road attributes that started with a blank form and added controls (lines, text boxes, labels and some graphs) each with event codes. It meant the user could click on any control and edit data and trigger events etc.

While this may not be an answer to your question directly, it IS possible to do what originally asked, but it is not particularly EASY to do.

Regards,
Pete.
 

Users who are viewing this thread

Back
Top Bottom