Solved

determining the field name in access vb

Posted on 2011-09-08
4
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
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…

752 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