Creating Form objects in Access from within a Module
16-08-2005, 14:55
|
#1
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
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
|
|
|
16-08-2005, 15:02
|
#2
|
|
Inactive
Join Date: Jun 2003
Location: Surrey
Age: 59
Services: Virgin stuff
Posts: 6,407
|
Re: Creating Form objects in Access from within a Module
Why not hide the label and make it visible on click ?
|
|
|
16-08-2005, 15:36
|
#3
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
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.
|
|
|
16-08-2005, 15:52
|
#4
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
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
|
|
|
16-08-2005, 16:00
|
#5
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Creating Form objects in Access from within a Module
Quote:
|
Originally Posted by gazzae
Have the label hidden then when you make it visable set where you want it to appear using label1.left and label1.top
|
Sorry, I guess I need to explain this a bit more clearly, my bad.....
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.
|
|
|
16-08-2005, 16:17
|
#6
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
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.
|
|
|
16-08-2005, 16:23
|
#7
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Creating Form objects in Access from within a Module
Quote:
|
Originally Posted by gazzae
Ah right, control arrays aren't supported in VBA AFAIK.
|
Ahh, that could be a problem then.....
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:
|
Originally Posted by gazzae
You could create a bodge job control array but that would mean having to create the labels yourself.
|
By hand, or with code?
Quote:
|
Originally Posted by gazzae
There is a CreateControl command in VBA but I remember it not working correctly.
|
Ah, sounds about right for MS and Access
Quote:
|
Originally Posted by gazzae
Do you have a copy of VB? You could use access as the backend and create your frontend in VB.
|
That would be a nice solution, we've actually got a SQL Server running here on the site so that would be even better. I've got VB6 at home so I could certainly knock something up.....
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
|
|
|
16-08-2005, 16:42
|
#8
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
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.
|
|
|
16-08-2005, 16:44
|
#9
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Creating Form objects in Access from within a Module
Quote:
|
Originally Posted by gazzae
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.
|
Hmmm......
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
Thanks very much.
|
|
|
16-08-2005, 17:20
|
#10
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
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"
|
|
|
16-08-2005, 17:31
|
#11
|
|
Inactive
Join Date: Jun 2003
Location: Surrey
Age: 59
Services: Virgin stuff
Posts: 6,407
|
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
|
|
|
16-08-2005, 17:44
|
#12
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Creating Form objects in Access from within a Module
Quote:
|
Originally Posted by Simon M
tbh, Access 95 was full of "features" such as this, you really would be better moving to a newer version. Sorry 
|
Yup
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
|
|
|
17-08-2005, 14:53
|
#13
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
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:
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.....
|
AFAIK, Access uses twips for measurement rather than inches which i assume you are using above, there are 1440 twips to 1 inch.
|
|
|
17-08-2005, 15:33
|
#14
|
|
Inactive
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
|
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:
Public Sub addlbl()
Dim lbl As Label
DoCmd.OpenForm "abc", acDesign
Set lbl = CreateControl("abc", acLabel, acDetail, , , 5000, 5000, 5000, 5000)
With lbl
.Caption = "HELLO"
.FontName = "ARIAL"
.FontBold = True
.FontSize = 11
.ForeColor = 255
End With
DoCmd.Close acForm, "abc", acSaveYes
DoCmd.OpenForm "abc"
End Sub
|
|
|
|
17-08-2005, 15:46
|
#15
|
|
Inactive
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
|
Re: Creating Form objects in Access from within a Module
Quote:
|
Originally Posted by gazzae
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.
|
You know what?
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
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 15:21.
|