Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Creating Form objects in Access from within a Module

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion
Register FAQ Community Calendar

Creating Form objects in Access from within a Module
Reply
 
Thread Tools
Old 16-08-2005, 14:55   #1
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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
Raistlin is offline   Reply With Quote
Advertisement
Old 16-08-2005, 15:02   #2
Nemesis
Inactive
 
Join Date: Jun 2003
Location: Surrey
Age: 59
Services: Virgin stuff
Posts: 6,407
Nemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny star
Nemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny star
Send a message via MSN to Nemesis
Re: Creating Form objects in Access from within a Module

Why not hide the label and make it visible on click ?
Nemesis is offline   Reply With Quote
Old 16-08-2005, 15:36   #3
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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.
Raistlin is offline   Reply With Quote
Old 16-08-2005, 15:52   #4
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
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
gazzae is offline   Reply With Quote
Old 16-08-2005, 16:00   #5
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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.
Raistlin is offline   Reply With Quote
Old 16-08-2005, 16:17   #6
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
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.
gazzae is offline   Reply With Quote
Old 16-08-2005, 16:23   #7
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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
Raistlin is offline   Reply With Quote
Old 16-08-2005, 16:42   #8
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
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.
gazzae is offline   Reply With Quote
Old 16-08-2005, 16:44   #9
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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.
Raistlin is offline   Reply With Quote
Old 16-08-2005, 17:20   #10
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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"
Raistlin is offline   Reply With Quote
Old 16-08-2005, 17:31   #11
Nemesis
Inactive
 
Join Date: Jun 2003
Location: Surrey
Age: 59
Services: Virgin stuff
Posts: 6,407
Nemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny star
Nemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny starNemesis has a nice shiny star
Send a message via MSN to Nemesis
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
Nemesis is offline   Reply With Quote
Old 16-08-2005, 17:44   #12
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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
Raistlin is offline   Reply With Quote
Old 17-08-2005, 14:53   #13
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
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.
gazzae is offline   Reply With Quote
Old 17-08-2005, 15:33   #14
gazzae
Inactive
 
gazzae's Avatar
 
Join Date: Jun 2003
Location: Belfast
Age: 46
Posts: 4,594
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
gazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronzegazzae is cast in bronze
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
gazzae is offline   Reply With Quote
Old 17-08-2005, 15:46   #15
Raistlin
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
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
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
Raistlin is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 13:59.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum