Solved

determining the field name in access vb

Posted on 2011-09-08
4
147 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 119

Expert Comment

by:Rey Obrero
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now