![]() |
Creating Form objects in Access from within a Module
Hi Guys,
Is there any way to create a label on a form within a module in Access? Say for example I have: frmMyForm (the form) butButton (the button) And I want to create lblMyLabel when butButton is clicked. I know I put this in the on_click event of the button but I can't figure out how to get access to create the label for me. If I wanted the label to have the following properties: Left = 6.998 Top = 3.598 Width = 5.399 Height = 2.400 Is that possible also? Thanks very much :) |
Re: Creating Form objects in Access from within a Module
Why not hide the label and make it visible on click ?
|
Re: Creating Form objects in Access from within a Module
The label could potentially be anywhere on the form.
The position of it will be determined by looking up the properties from a seperate table at the time when it is created. |
Re: Creating Form objects in Access from within a Module
Have the label hidden then when you make it visible set where you want it to appear using label1.left and label1.top
|
Re: Creating Form objects in Access from within a Module
Quote:
The module to create the label will be need to be used to dynamicaly create the label. The form could (in theory) have just one label on it or many labels - it's not actually possible to predict what labels will be on the form in advance, that's why they need to be created on an ad-hoc basis. |
Re: Creating Form objects in Access from within a Module
Ah right, control arrays aren't supported in VBA AFAIK.
You could create a bodge job control array but that would mean having to create the labels yourself. There is a CreateControl command in VBA but I remember it not working correctly. __________________ Do you have a copy of VB? You could use access as the backend and create your frontend in VB. |
Re: Creating Form objects in Access from within a Module
Quote:
Do I actually need a control array though? All I need to be able to do is create a control, assign the properties, give it a name..... It wouldn't persist once the form was closed. Quote:
Quote:
Quote:
The only problem with that is that (because of the restrictions on our usage of the machines, and on what we can put on the network) we would never get it approved for use at work. We're still using NT and Access 95 - that should give you an idea of how much fun we have :( |
Re: Creating Form objects in Access from within a Module
Been looking into this, the CreateControl does work, but you need to put the form into design mode, create the labels using CreateControl, save the form, close it and re-open it in form view.
|
Re: Creating Form objects in Access from within a Module
Quote:
I suppose that's not too much of a problem - unless, of course, the user only has "Read Only" access to the Form, but that's not likely to be the case. I'll have a look at that and see if I can work it out from that :tu: Thanks very much. |
Re: Creating Form objects in Access from within a Module
Ok, something weird's happening.
In the on_click event for butButton I've got: CreateControl (frmMyForm,acLabel,acDetail,,,6.998,3.598,5.399,2. 4) As Control Which should be the correct formatting for that function..... Whenever I hit return at the end of the line, or space, or try to save the form, the database just shuts down (no error messages or anything) and I get returned to the desktop. The .ldb is still open and I need to open and then reclose the database to clear the .ldb file. When I do this Access doesn't save the new line of code. Any ideas what's causing this? I'm sure it's not a problem with the code, so I'm guessing that it must be a "feature" :rolleyes: |
Re: Creating Form objects in Access from within a Module
tbh, Access 95 was full of "features" such as this, you really would be better moving to a newer version. Sorry :(
|
Re: Creating Form objects in Access from within a Module
Quote:
Unfortunately I am seriously constrained as to what I can use..... This would be soooooo much easier if they would just let me use VB :) But they won't :( |
Re: Creating Form objects in Access from within a Module
You know you might be better using a module and creating the whole form programmatically rather than trying to add controls to a form already open.
Quote:
|
Re: Creating Form objects in Access from within a Module
Here is a simple module I just wrote. It opens a already designed form in design view, adds a label, closes and saves the form and then reopens it in form view. Hope this helps.
Quote:
|
Re: Creating Form objects in Access from within a Module
Quote:
You're a bl**dy star!!! I've been fiddling with that since yesterday, I think I even tried something like what you've done above - it just wouldn't work. I don't know what to say, other than Thank You. If we ever meet up the beers are on me :tu: |
| All times are GMT. The time now is 13:07. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum