By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,248 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,248 IT Pros & Developers. It's quick & easy.

Method error when adding a control object using VB

P: n/a
Ben
Access 2000 using VB

I have been trying to add a control using VB but have been running
into the problem: Compile error: Method or data member not found

I have tried several examples including the one from the help file.
The latest one I have tried is:

Option Compare Database

Dim Mycmd As Control
Dim MyLabelName As String
Dim MyLabelCaption As String

Private Sub Command1_Click()

Dim Mycmd As Control
Dim MyLabelName As String
Dim MyLabelCaption As String

For n = 1 To 5
MyLabelName = "Label" & n
MyLabelCaption = "This is label number " & n
Set Mycmd = Controls.Add("Forms.Label.1", MyLabelName, Visible)
Mycmd.Left = 20
Mycmd.Top = n * 15
Mycmd.Width = 100
Mycmd.Height = 20
Mycmd.Caption = MyLabelCaption
Next n

End Sub

When it compiles I get that error with the ".Add" blue selected. I am
assuming that I probably do not have the correct reference selected
but I have no idea which one. I have tried a couple of ones that
looked promising.

I am probably missing something very simple.

Thanks in advance.
Ben
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
be****@hotmail.com (Ben) wrote in message news:<bd**************************@posting.google. com>...
Access 2000 using VB

I have been trying to add a control using VB but have been running
into the problem: Compile error: Method or data member not found

I have tried several examples including the one from the help file.
The latest one I have tried is:

Option Compare Database

Dim Mycmd As Control
Dim MyLabelName As String
Dim MyLabelCaption As String

Private Sub Command1_Click()

Dim Mycmd As Control
Dim MyLabelName As String
Dim MyLabelCaption As String

For n = 1 To 5
MyLabelName = "Label" & n
MyLabelCaption = "This is label number " & n
Set Mycmd = Controls.Add("Forms.Label.1", MyLabelName, Visible)
Mycmd.Left = 20
Mycmd.Top = n * 15
Mycmd.Width = 100
Mycmd.Height = 20
Mycmd.Caption = MyLabelCaption
Next n

End Sub

When it compiles I get that error with the ".Add" blue selected. I am
assuming that I probably do not have the correct reference selected
but I have no idea which one. I have tried a couple of ones that
looked promising.

I am probably missing something very simple.

Thanks in advance.
Ben


I think you need CreateControl, rather than Add. Have a look in the
help under CreateControl
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.