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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controls collection question 1

Status
Not open for further replies.

Terpsfan

Programmer
Dec 8, 2000
954
US
I have a procedure in my individual form modules that enumerates through the Controls collection to set a default value to all the combobox controls. I tried putting this procedure in a standard module and calling it from the form module. However, when I try to run it from the standard module I get an error that says I need to Declare a variable for Controls. It runs fine from the form module. What declaration should I use for Controls in a standard module? Thanks

Public Sub NullValues()
'Assigns a default value to each combo box control
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is ComboBox Then
ctl.DefaultValue = """No"""
End If
Next ctl
End Sub
 
You must pass the full path to the controls to the subroutine.

Public Sub NullValues(frm As Form)
'Assigns a default value to each combo box control
Dim ctl As Control
For Each ctl In frm.Controls
If TypeOf ctl Is ComboBox Then
ctl.DefaultValue = """No"""
End If
Next ctl
End Sub

To call the routine would be:

NullValues(Me)
 
Unfortunately when I tried to call the procedure I got a Type Mismatch error. I typed it exactly as shown above.
 
Okay, it worked when I used an Explicit Call statement, i.e. Call NullValues(Me). Thanks a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top