RunTime Error 429

J

James Nap

When I run the following code I get a runtime error 429
ActiveX compoent can't create object.

dim cmdBtn as CommandButton

set cmdBtn = New CommandButton

It fails on the set line.

Thanks
 
D

Dirk Goldgar

James Nap said:
When I run the following code I get a runtime error 429
ActiveX compoent can't create object.

dim cmdBtn as CommandButton

set cmdBtn = New CommandButton

It fails on the set line.

Thanks

I don't believe you can use the "New" syntax to create an Access command
button. Instead, you have to use the CreateControl method of an
existing Form object to create the control. See the help file entry for
"CreateControl Method" for an example.
 
J

James Nap

What I would like to do is loop through some of the
existing command buttons on a form and change their
caption property. Only the command buttons and not all of
them.

Thanks.
 
D

Dirk Goldgar

James Nap said:
What I would like to do is loop through some of the
existing command buttons on a form and change their
caption property. Only the command buttons and not all of
them.

I have a few questions for you:

1. Of all the command buttons on the form, how will you (or the code)
know which command buttons to modify?

2. Will the code be running on the form itself, or in some other form or
module?

3. Are the captions to be changed at run time, and just for the moment,
or are you wanting to change them permanently (in design view), so that
the next time the form is opened the changed captions appear?
 
D

Dirk Goldgar

James Nap said:
The captions will be changed at runtime based on a user
supplied value in a combobox. They will continue to change
as the value changes. Also all this will happen on the
same form. The command buttons that need to be changed
have names: commmand0 through command40.

I was hoping to be able to initialize the cmdbtn
commandbutton variable and using a for...next loop iterate
through the loop changing the caption property.

Thanks

Sure, you can do this easily, but not the way you were going about it.
Try something like this:

'----- start of sample code -----
Dim i As Integer

For i = 0 to 40
With Me.Controls("Command" & i)
.Caption = "whatever"
End With
Next i
'----- end of sample code -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top