Solved

determining the field name in access vb

Posted on 2011-09-08
4
149 Views
Last Modified: 2012-05-12
I'm writing a common function to apply to several fields on a form.  I want to be able to reset the field value based upon certain conditions.  Right now, I can do it per field.  Is there a way to capture the field name so that I can pass it to the common function?  That way, I only have to code it once.

Thanks for the help,
je
0
Comment
Question by:aeolianje
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36502411
in a form you use control not field (field is the unit in a table)

sample code to get control names
dim ctl as control
for each ctl in forms!nameofForm.controls
   
    debug.print ctl.name
next
0
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 36502519
If you are looking for the name of the control that the user is currently focused on (such as the name of a textbox or combo currently being used):

msgbox Screen.ActiveControl.Name

If you are looking for the FIELD that the currently focused control is bound to (ie the field in the underlying table or query):

msgbox Screen.ActiveControl.controlsource
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36503594
Do you mean:
<I'm writing a common function to apply to several Controls on a form.  I want to be able to reset the Control value based upon certain conditions.  Right now, I can do it per Control .  Is there a way to capture the field name from the Control, so that I can pass it to the common function?  That way, I only have to code it once.>
?

A form can have fields and controls
A control can be named the same thing as the field.
A control can be bound or unbound.
I bound, it can be bound in at leaset two ways:
 YourField
...or:
=YourField


...So the distinction between a "Field" and a "control" on a form needs to very clear...

JeffCoachman
0
 

Author Closing Comment

by:aeolianje
ID: 36817437
Thanks for your help.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Some sers suddenly getting error popup msg 28 86
hit enter key to run macro 13 23
Column Layout in Access Xp VBA Report 3 19
No Data for DropDown List 2 22
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question