How Do I check if a form, whose name I can detect as a passed object, has a control of a specific na

  • Thread starter Thread starter rg
  • Start date Start date
R

rg

I have code running that sets values on different forms.

Most of the forms have the same named controls for certain data fields and
some unfortunately do not. We can not alter the forms because of legacy
issues.

How do I check if a form contains a control with a specific name?

TIA

Regards,

Roy
 
You could attempt to get the controls name property and trap the error -
2465 <<Database name>> can't find the field '<<>>' referred to in your
expression.

Dim strName as String

strName = Forms!YourFormname!YourControlName



Or you could loop through all the controls on the form and see if the name
existed for the control.

Dim ctrlAny as Control
Dim tfExists as Boolean

For each ctrlAny in Forms!Formname.Controls
if ctrlAny.Name = PassedInNameForControl Then tfExists = True
Next ctrlANy

If tfExists = True then
...
 
Hi Roy,

How about creating a table ControlNames with fields

FormName*
FieldName*
ControlName

Then use DLookup to get the correct ControlName for the form and field
you need.
 
This should solve my need.

Much Obliged!


John Spencer said:
You could attempt to get the controls name property and trap the error -
2465 <<Database name>> can't find the field '<<>>' referred to in your
expression.

Dim strName as String

strName = Forms!YourFormname!YourControlName



Or you could loop through all the controls on the form and see if the name
existed for the control.

Dim ctrlAny as Control
Dim tfExists as Boolean

For each ctrlAny in Forms!Formname.Controls
if ctrlAny.Name = PassedInNameForControl Then tfExists = True
Next ctrlANy

If tfExists = True then
...
 

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

Back
Top