Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More Box Names in Word 1

Status
Not open for further replies.

DLG0311

Technical User
Jan 6, 2005
13
GB
Can Some explain why this code fails

For Each Control In Controls
MyControl = Control.Name: ContName = Left(Control.Name, 4)
If ContName = "VATC" Then
With MyControl
.AddItem "1 - Outside the Scope"
.AddItem "2 - Exempt"
.AddItem "3 - Zero Rated"
.AddItem "4 - Standard Rate (17.5%)"
.AddItem "5 - Reduced Rate (Domestic Fuel etc.)"
.AddItem "6 - Inclusive of VAT at 17.5%"
End With
Else
End If
Next

This cycles through all the Text Boxes etc until it finally finds the first ComboBox "VATC1" (can this route be shortened to look only for Combo Boxes?) it then drops into the With code. MyControl DOES contain the Control Name "VATC1" so that works, but when it tries to run the code ".AddItem "1 - Outside the Scope"", it fails with error message "Run time error 424 - Object Required"

Can someone guid/assist me further please
 
Hi DLG0311,

I'm not quite sure what you have set Controls to but assuming that bit of it works (as you say it does) you don't need (or want) the complication of MyControl (which you have as a string, not an object). Try simplifying it to:
Code:
[blue]For Each Control In Controls
    With Control
        If Left(.Name, 4) = "VATC" Then
            .AddItem [green]etc., etc.
            :[/green]
        End If
    End With
Next[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top