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

Programmatically detect if control exists?

Status
Not open for further replies.

Custardptt

Technical User
Jan 12, 2005
31
0
0
GB
Hi All,

Is there an easy way to detect if a control exists in an access form programmatically?

I have code that attempts to set the value of a checkbox (having retrieved the name of the checkbox from a lookup table). Problem is the lookup up table may contain the names of controls that are not on my form.

The code I’m using to set the object values is (this is part of a loop):-
Set myObject = Me.Controls(myRST("DControlName"))
myObject = myRST("DControlValue")

I want to detect if the control exists before attempting to set its value.

Any Thoughts

Many Thanks

Pete
 
You may try something like this:
Dim ctl As control
For Each ctl in Me.Controls
If ctl.Name = "DControlName" Then
ctl.Value = myRST("DControlValue")
Exit For
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top