Solved

determining the field name in access vb

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query to summarise data Like Pivot Table 3 29
Get Top Visible Row of Datagridview 6 28
Excess tables to Excel BackUp 3 29
field number type in access tabledefs fields 5 20
This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

862 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

24 Experts available now in Live!

Get 1:1 Help Now