Indirect reference

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi,

In Oracle Forms I can indirectly reference a textbox eg.

IF :empname = 'smith' -- direct reference

IF NAME_IN('empname') = 'smith' -- indirect reference (assigns the
value 'smith' into the textbox named :empname

Or Copy('smith','empname') -- indirect reference (copies the value
'smith' into the textbox named :empname

By referencing items indirectly I can write more generic, reusable
code.

Now I would like to do the same with my Access application. How can
this be done or can it be done at all?

Eg. I would like to create a common Subprocedure in a Module where I
can pass in the name of any textboxes and then apply methods on the
textboxes within the Subprocedure.

Many thanks!
 
Set up parameters for your function:

Public Function CopyValue(strToCopy As String, TextBoxToCopyItTo As TextBox)
TextBoxToCopyItTo.Value = strToCopy
End Function

Call it:
CopyValue "test", txtTestField

You can make it even more generic by changing the TextBoxToCopyItTo As
TextBox to something like ControlToCopyItTo As Control. Now, you'll need to
check the control type and deal with it appropriately depending on the type.

--
Troy

Troy Munford
Development Operations Manager
FMS, Inc.
www.fmsinc.com


Hi,

In Oracle Forms I can indirectly reference a textbox eg.

IF :empname = 'smith' -- direct reference

IF NAME_IN('empname') = 'smith' -- indirect reference (assigns the
value 'smith' into the textbox named :empname

Or Copy('smith','empname') -- indirect reference (copies the value
'smith' into the textbox named :empname

By referencing items indirectly I can write more generic, reusable
code.

Now I would like to do the same with my Access application. How can
this be done or can it be done at all?

Eg. I would like to create a common Subprocedure in a Module where I
can pass in the name of any textboxes and then apply methods on the
textboxes within the Subprocedure.

Many thanks!
 
David said:
In Oracle Forms I can indirectly reference a textbox eg.

IF :empname = 'smith' -- direct reference

IF NAME_IN('empname') = 'smith' -- indirect reference (assigns the
value 'smith' into the textbox named :empname

Or Copy('smith','empname') -- indirect reference (copies the value
'smith' into the textbox named :empname

By referencing items indirectly I can write more generic, reusable
code.

Now I would like to do the same with my Access application. How can
this be done or can it be done at all?

Eg. I would like to create a common Subprocedure in a Module where I
can pass in the name of any textboxes and then apply methods on the
textboxes within the Subprocedure.


In spite of appearances allowed by defaulted syntax
components, you do not refer to textbox (or any control)
directly. You are really referring to an item in the
Controls collection returned by the form object's Controls
property (it pays to understand the details of the object
model, not just some common syntax). Eg. When you write
empname in a line of code, you are using the default object
(the form containing the code) and it's Controls collection.
The full reference for this is
Me.Controls.Item("empname").Value
but almost everyone omits the default Item property and the
explicit use of the Value property. So that would ,ore
likely be written as
Me.Controls("empname")
A lot of people also don't bother writing the Controls
property either, so it then shortens to any of:
Me!empname
Me.empname
Me("empname")
Are you confused yet? ;-)

With that lecture under your belt, the answer to your
question is to use the syntax:

strcontrol = "empname"
. . .
Me(strcontrol)
 
David said:
Hi,

In Oracle Forms I can indirectly reference a textbox eg.

IF :empname = 'smith' -- direct reference

IF NAME_IN('empname') = 'smith' -- indirect reference (assigns the
value 'smith' into the textbox named :empname

Or Copy('smith','empname') -- indirect reference (copies the value
'smith' into the textbox named :empname

By referencing items indirectly I can write more generic, reusable
code.

The sytax in ms-access if very simmlu

if me!LastName = 'smith' --- direct refernce

if me("LastName") = 'smith' --- indirect refe

So, you can go:

strWhatField = "LastName"

if me(strWhatField) = 'smith' indirect ref
 
Thanks guys for all the useful inputs. Feels great when the prog works
after all your help.
 
Back
Top