Log in

View Full Version : Error when creating control



19701
10-03-2005, 04:45 AM
I get an error message when I try to run this...

Error num: 3799

Cant find label 'label134'

When I try to run it on a different form it works fine how come its not working on my form "Articulo". Ill be happy to supply with more info if needed.

Sub NewControls()
Dim ctlLabel As Control
Dim intLabelX As Integer, intLabelY As Integer

DoCmd.OpenForm "Articulo", acDesign
' Set positioning values for new controls.
intLabelX = 1000
intLabelY = 100
' Create child label control for text box.
Set ctlLabel = CreateControl(Forms!Articulo.Name, acLabel, , , "NewLabel", intLabelX, intLabelY)
' Restore form.
DoCmd.Restore
DoCmd.OpenForm "Articulo"
End Sub

geekgirlau
10-03-2005, 05:09 AM
Welcome 19701!

I've edited your post to put VBA tags around your code - you can do this by selecting your text and clicking on the "VBA" button.

Could you post the CreateControl procedure?

chocobochick
10-03-2005, 06:03 AM
It looks like CreateControl() is yet another built-in Access function that Microsoft didn't bother to document in their help files... at least in my version of Access 2000, anyway. However, I did finally find the syntax (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac10/html/acmthCreateControl.asp) for it. With that in mind, my first two questions are:

Why did you set the ColumnName parameter to "NewLabel"? Even if Articulo's recordset table contained a field by this name, a label cannot be a data-bound control anyway. Does this serve another purpose?
By any chance is your form less than 0.7" wide (1000 twips), or the Detail section less than .07" tall (100 twips)?
Try omitting all the optional arguments of CreateControl, using just this:

Set ctlLabel = CreateControl(Forms!Articulo.Name, acLabel)


If that works, try including the additional parameters one by one to see what causes the error.

Norie
10-03-2005, 12:40 PM
chocobochick

CreateControl is documented in Help. I think you would need to goto Access VBA Help to find it, and a lot of other things too. :)

CreateControl, CreateReportControl Methods





The CreateControl method creates a control (http://javascript<b></b>:HelpPopup('actip9.hlp','defControl');) on a specified open form.
The CreateReportControl method creates a control on a specified open report.
For example, suppose you are building a custom wizard that allows users to easily construct a particular form. You can use the CreateControl method in your wizard to add the appropriate controls to the form.

Syntax

CreateControl(formname, controltype[, section[, parent[, columnname[, left[, top[, width[, height]]]]]]])

CreateReportControl(reportname, controltype[, section[, parent[, columnname[, left[, top[, width[, height]]]]]]])

geekgirlau
10-04-2005, 11:01 PM
Thanks Norie - haven't had an opportunity to use this one, but yep I did find it when I had a proper look :doh:.

How are you going with this 19701? Have you tried Chocobochick's suggestions?