Determining control field type (from the form control)

Is there a fast/clean way of determining the field type (directly from the form)?  I have a function that creates a shortcut menu when a control gets focus (pretty much every field/control on the form will do this).  

Some of the options on this shortcut are in relation to filtering, and I want to be able to determine the actual field type (not the value within the field).  I know that I can pole the table directly with something like this (ctl.name is the field that has focus).

currentdb.TableDefs("_tblMain").Fields(ctl.name).type

However, if there is a better way without looking at the table directly, I think it might be more efficient.
Andy BrownDeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
I don't think the Form itself has any knowledge of the Datatype of the fields bound to controls. Your method should work fine, but unless you're using the Field name as the Control name (which is a bad idea), then you would need something like this:

CurrentDb.TableDefs("Table1").Fields(Me.Worked_Department.ControlSource).Type

The highlighted portion would be changed for each control.
0
 
Andy BrownDeveloperAuthor Commented:
Yep - I just spotted that one :O)

Thanks for the help.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
A better option, although less automatic, would be to use the controls tag property.  

 This would give you more granular control over what controls allow for filtering, and the type of filtering that should be used.

Jim.
0
 
Andy BrownDeveloperAuthor Commented:
Thanks Jim (as always).  I'll take a look.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.