473,396 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Method error when adding a control object using VB

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
1 2494
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eamonn O'Connell | last post by:
Hi, We have an ASP.net application, where we dynamically add controls, in the Page_Load. Occasionally, when the user posts back the page (e.g. clicks Save button on the page), we get a "Failed...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Steve Jorgensen | last post by:
When writing VB or VBA code that works with databases or other external libraries that cannot be trusted to automatically do the right thing when references to their objects are arbitrarily...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
1
by: Michael | last post by:
Hi, Any one know the problem of the following error: Thanks, m Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
0
by: fniles | last post by:
I created a CAB file for a 3rd party control (StockChartX) it using CABARC.exe that comes from Microsoft SDK. In the CAB file I included the StockChartX.ocx and StockChartX.INF. Then, I signed the...
4
by: rushikesh.joshi | last post by:
Hi All, I have created my own WebControl and want to add it in my aspx page at runtime. it's compiling perfectly, but when i m going to execute, it gives me error of "Object reference not set...
4
by: scottcly | last post by:
I have a simple editor with a Gridview and a DetailsView. The Gridview handles DELETE and the DetailsView handles UPDATE and ADD. A panel around each one and some minor event handling is used to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.