Solved

determining the field name in access vb

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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 …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

632 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