Creating labels in Runtime

Trogdor

Registered User.
Local time
Tomorrow, 05:14
Joined
Oct 22, 2008
Messages
32
Hey,

I know people will be wondering why I even want to do this, but first let me explain.

I am developing a database which is capturing date/time of events taking place, and I have incorporated the drag/drop functionality which I found on a thread on this site.

The Drag and drop allows the user to drag and drop labels any where around the form. I have made it so that when the label is in certain areas of the form it creates a new line in a table recording the appropriate data.

What I want however is to have an endless stream of labels available to me, so I want to make it dynamic. So when you pick up the first label it will create another label under it so i can have an infinite amount of objects in my database. I need it to do this in run-time.

Currently I have 7 labels statically in my form for testing purposes.

Does anyone know a way in which I can dynamically create labels?

Cheers
 
Trogdor,

Very nice idea, BUT Access imposes limitations on form controls. I don't
know the exact number, but you are limited to something like 754 controls
during the life of a form.

Even if you "clean up" by deleting them later, Access will remember. You
might only have 15 or 20 controls currently, but still exhaust Access's max
value.

I think you'll have to figure out a way to reuse your static controls.

Wayne
 
just to let people know, I found this on another forum but i couldn't get the code to work for myself. I am using Access 2007.

Private Sub LabelIntro()

Dim lbl As MSForms.label

Set lbl = Me.Controls.Add("Forms.Label.1")
With lbl
.Top = 10
.Left = 5
.Height = 20
.Width = 40
.Caption = "TED"
End With

End Sub


http://www.ozgrid.com/forum/showthread.php?t=48349
 
Okay so I have come up with a new way to do it but need some help.. Instead I now have 20 static labels which I loop through, but what i want to do is when i discard a lablel i want to change it's name using something like:

lbl.name = mid(lbl.name, 1, 7) & int(mid(lbl.name,8) + 20)

so that this will give the appearance of an infinite number of labels when in reality it is just hashing over the old ones over and over with a new badge so to speak.

Problem I am facing now is error 2136 I think, cant change this in runtime. Is there a way around this? why is access such a pain with things like this?

let me know :)

Cheers!
 
Can you post an example of you db to view and hopefully provide a solution.
 
here is the part of the code I am using to redraw the label


Sub reset_square(squareID)

Dim albActionLabel As clsActionLabel
Dim lbl As label

Set mcolActionLabels = New Collection

Set albActionLabel = New clsActionLabel
Set lbl = Forms![frmMain]("lblTest" & Trim(Str(squareID)))
Set albActionLabel.label = lbl
albActionLabel.OnMouseMove = "OnLabelMouseMove"
albActionLabel.OnMouseUp = "OnLabelMouseUp"

mcolActionLabels.Add albActionLabel, albActionLabel.label.Name

lbl.height = conDefaultSizeY
lbl.width = conDefaultSizeX
lbl.top = 160
lbl.BackColor = RGB(0, 255, 0)
lbl.Left = 5100
lbl.caption = ""
lbl.Name = Mid(lbl.Name, 1, 7) & Int(Mid(lbl.Name, 8) + 20)

End Sub

not sure what you need though.
 
You can't change a controls name or create a new control on a form during runtime, you need to open the form in design view and then you can change the name or create new controls. Basically this means having the code that does this in a public module or in another form, a form can't change the names of it's own controls.
 

Users who are viewing this thread

Back
Top Bottom