Using a variable

M

Mark

I have what I think is a straight forward question which eludes me. I want to
pass a variable to a procedure which in turn is used in the following:
Passed variable = "txtAmountPd" This is always going to be a text box.
Msgbox Forms![FlatFileData]. Passed variable .Tag (or other property.)
I need to use the variable in this fashion either on the form,
Me! Passed variable …..
Or in a module as Forms![FlatFileData]. Passed variable …..
What is the correct syntax????
Thanks,
M
 
B

BruceM

It would depend on the procedure to which you wish to pass the variable,
among other things. What specifically are you trying to do, and what result
do you wish to obtain?
 
M

Mark

I want to pass an object (text box) to a procedure which modifies properties
of that object with this type of syntax: Masterform.[passed
variable].property = something

BruceM said:
It would depend on the procedure to which you wish to pass the variable,
among other things. What specifically are you trying to do, and what result
do you wish to obtain?


Mark said:
I have what I think is a straight forward question which eludes me. I want
to
pass a variable to a procedure which in turn is used in the following:
Passed variable = "txtAmountPd" This is always going to be a text box.
Msgbox Forms![FlatFileData]. Passed variable .Tag (or other property.)
I need to use the variable in this fashion either on the form,
Me! Passed variable ...
Or in a module as Forms![FlatFileData]. Passed variable ...
What is the correct syntax????
Thanks,
M
 
B

BruceM

Pass it as a procedure argument.

Mark said:
I want to pass an object (text box) to a procedure which modifies
properties
of that object with this type of syntax: Masterform.[passed
variable].property = something

BruceM said:
It would depend on the procedure to which you wish to pass the variable,
among other things. What specifically are you trying to do, and what
result
do you wish to obtain?


Mark said:
I have what I think is a straight forward question which eludes me. I
want
to
pass a variable to a procedure which in turn is used in the following:
Passed variable = "txtAmountPd" This is always going to be a text
box.
Msgbox Forms![FlatFileData]. Passed variable .Tag (or other
property.)
I need to use the variable in this fashion either on the form,
Me! Passed variable ...
Or in a module as Forms![FlatFileData]. Passed variable ...
What is the correct syntax????
Thanks,
M
 
M

Mark

I am. What I need to understand is after I have it in the procedure, what is
the proper syntax??????

BruceM said:
Pass it as a procedure argument.

Mark said:
I want to pass an object (text box) to a procedure which modifies
properties
of that object with this type of syntax: Masterform.[passed
variable].property = something

BruceM said:
It would depend on the procedure to which you wish to pass the variable,
among other things. What specifically are you trying to do, and what
result
do you wish to obtain?


I have what I think is a straight forward question which eludes me. I
want
to
pass a variable to a procedure which in turn is used in the following:
Passed variable = "txtAmountPd" This is always going to be a text
box.
Msgbox Forms![FlatFileData]. Passed variable .Tag (or other
property.)
I need to use the variable in this fashion either on the form,
Me! Passed variable ...
Or in a module as Forms![FlatFileData]. Passed variable ...
What is the correct syntax????
Thanks,
M
 
B

BruceM

To pass the Tag property to a message box:, assuming the Tag property is on
the current form:

MsgBox Me.ControlName.Tag

If it is on another form:

MsgBox Forms![FormName]![ControlName].Tag

That's as much as I can tell you unless you are willing to say exactly what
you are trying to do. To what procedure are you trying to pass a property?
Change it how, and do what with it after it is changed? Your question is
along the lines of asking what size wrench to use to tighten a bolt. It all
depends on the details.

Mark said:
I am. What I need to understand is after I have it in the procedure, what
is
the proper syntax??????

BruceM said:
Pass it as a procedure argument.

Mark said:
I want to pass an object (text box) to a procedure which modifies
properties
of that object with this type of syntax: Masterform.[passed
variable].property = something

:

It would depend on the procedure to which you wish to pass the
variable,
among other things. What specifically are you trying to do, and what
result
do you wish to obtain?


I have what I think is a straight forward question which eludes me. I
want
to
pass a variable to a procedure which in turn is used in the
following:
Passed variable = "txtAmountPd" This is always going to be a
text
box.
Msgbox Forms![FlatFileData]. Passed variable .Tag (or other
property.)
I need to use the variable in this fashion either on the form,
Me! Passed variable ...
Or in a module as Forms![FlatFileData]. Passed variable ...
What is the correct syntax????
Thanks,
M
 
G

GeoffG

Does this answer your question?

Public Sub SetTextBoxValue(objTXT As Access.TextBox)

objTXT.Value = Me.txtAmountPaid
objTXT.Tag = "My tag"

End Sub


Geoff





Mark said:
I am. What I need to understand is after I have it in the
procedure, what is
the proper syntax??????

BruceM said:
Pass it as a procedure argument.

Mark said:
I want to pass an object (text box) to a procedure which
modifies
properties
of that object with this type of syntax:
Masterform.[passed
variable].property = something

:

It would depend on the procedure to which you wish to
pass the variable,
among other things. What specifically are you trying
to do, and what
result
do you wish to obtain?


message
I have what I think is a straight forward question
which eludes me. I
want
to
pass a variable to a procedure which in turn is used
in the following:
Passed variable = "txtAmountPd" This is always
going to be a text
box.
Msgbox Forms![FlatFileData]. Passed variable .Tag
(or other
property.)
I need to use the variable in this fashion either on
the form,
Me! Passed variable ...
Or in a module as Forms![FlatFileData]. Passed
variable ...
What is the correct syntax????
Thanks,
M
 
M

Mark

Apparently my comm is bad. Let me put like this. In a module one can change
an objects property with this syntax,
Forms![FlatFileData].[lblSort].Caption = “Caption hereâ€
The form name is “FlatFileDataâ€
The label is name “lblSortâ€
Hopefully no arguments with that.
OK, now what I want to do is pass the object (in this case lblSort) to that
line of code. I assuming that it can’t be done and I found another way to
accomplish the same thing.
Let me break this down further. As an on click event on any object, I want
to call this line of code passing that objects name. In doing this I can
change any objects property without writing code for each object.


BruceM said:
To pass the Tag property to a message box:, assuming the Tag property is on
the current form:

MsgBox Me.ControlName.Tag

If it is on another form:

MsgBox Forms![FormName]![ControlName].Tag

That's as much as I can tell you unless you are willing to say exactly what
you are trying to do. To what procedure are you trying to pass a property?
Change it how, and do what with it after it is changed? Your question is
along the lines of asking what size wrench to use to tighten a bolt. It all
depends on the details.

Mark said:
I am. What I need to understand is after I have it in the procedure, what
is
the proper syntax??????

BruceM said:
Pass it as a procedure argument.

I want to pass an object (text box) to a procedure which modifies
properties
of that object with this type of syntax: Masterform.[passed
variable].property = something

:

It would depend on the procedure to which you wish to pass the
variable,
among other things. What specifically are you trying to do, and what
result
do you wish to obtain?


I have what I think is a straight forward question which eludes me. I
want
to
pass a variable to a procedure which in turn is used in the
following:
Passed variable = "txtAmountPd" This is always going to be a
text
box.
Msgbox Forms![FlatFileData]. Passed variable .Tag (or other
property.)
I need to use the variable in this fashion either on the form,
Me! Passed variable ...
Or in a module as Forms![FlatFileData]. Passed variable ...
What is the correct syntax????
Thanks,
M
 
B

BruceM

Understand that I am not arguing. You are looking at your database, but I
am not. What is obvious to you can only be conveyed by describing it. Your
description is a bit short on details.

There are class modules, including the code module for the form or report,
and there are standard modules, which are standalone code modules. Saying
that you can do something in a module is still rather vague, since the
module is a place to store procedures (subs and functions) and other code.

If you show how you did this (the other way you mentioned) it may well be
possible to see just what you are doing, and suggest a way to automate it,
but the closest I can come is that you want to click on a label and change
its caption to its name, which doesn't seem to make any sense, so I won't go
further down that road.


Mark said:
Apparently my comm is bad. Let me put like this. In a module one can
change
an objects property with this syntax,
Forms![FlatFileData].[lblSort].Caption = "Caption here"
The form name is "FlatFileData"
The label is name "lblSort"
Hopefully no arguments with that.
OK, now what I want to do is pass the object (in this case lblSort) to
that
line of code. I assuming that it can't be done and I found another way to
accomplish the same thing.
Let me break this down further. As an on click event on any object, I want
to call this line of code passing that objects name. In doing this I can
change any objects property without writing code for each object.


BruceM said:
To pass the Tag property to a message box:, assuming the Tag property is
on
the current form:

MsgBox Me.ControlName.Tag

If it is on another form:

MsgBox Forms![FormName]![ControlName].Tag

That's as much as I can tell you unless you are willing to say exactly
what
you are trying to do. To what procedure are you trying to pass a
property?
Change it how, and do what with it after it is changed? Your question is
along the lines of asking what size wrench to use to tighten a bolt. It
all
depends on the details.

Mark said:
I am. What I need to understand is after I have it in the procedure,
what
is
the proper syntax??????

:

Pass it as a procedure argument.

I want to pass an object (text box) to a procedure which modifies
properties
of that object with this type of syntax: Masterform.[passed
variable].property = something

:

It would depend on the procedure to which you wish to pass the
variable,
among other things. What specifically are you trying to do, and
what
result
do you wish to obtain?


I have what I think is a straight forward question which eludes
me. I
want
to
pass a variable to a procedure which in turn is used in the
following:
Passed variable = "txtAmountPd" This is always going to be a
text
box.
Msgbox Forms![FlatFileData]. Passed variable .Tag (or other
property.)
I need to use the variable in this fashion either on the form,
Me! Passed variable ...
Or in a module as Forms![FlatFileData]. Passed variable ...
What is the correct syntax????
Thanks,
M
 
J

John W. Vinson

Apparently my comm is bad. Let me put like this. In a module one can change
an objects property with this syntax,
Forms![FlatFileData].[lblSort].Caption = “Caption here”
The form name is “FlatFileData”
The label is name “lblSort”
Hopefully no arguments with that.
OK, now what I want to do is pass the object (in this case lblSort) to that
line of code. I assuming that it can’t be done and I found another way to
accomplish the same thing.

The form's Controls collection can be used in this way:

Forms![FlatFileData].Controls("lblSort").Caption =

In place of "lblSort" you can use a string variable or another form object
reference, just so long as it returns the name property of the desired
control.
 
B

BruceM

In my testing there seems to be no way a label can be the active control.
From what I can tell the OP wants to change a label caption without
specifically naming the label. If I loop through the controls, limiting the
list to acLabel, I can get the names of all labels on the form. If there is
a naming convention it should be possible then to change a specific label's
caption (if it has something in common with a text box name, for instance),
but I can't find a way to click on a label and get it to tell me its name.
I say the OP seems to have wanted to change a label caption, but in an
earlier point in the thread it was about a text box. In the end he seems to
have decided that what he wanted couldn't be done the way he wanted, but I
never was quite clear about what that may be.

KenSheridan via AccessMonster.com said:
You can use a form's ActiveControl property to identify the current
control.
But if you wish to call a procedure from any form you'd also need to
include
an argument to accept the form's name if you use one which accepts the
name
of the control, both declared as String. Then you can them pass them like
so:


Dim ctrl as Control
Dim strFormName as String
Dim strControlName As String

Set ctrl = Me.ActiveControl
strControlName = ctrl.Name
strFormName = Me.Name

MyProcedure strFormName, strControlName

in which case the procedure would be declared like this:

Sub MyProcedure (strFormName As String, strControlName As String)

and the code in the procedure would be something like:

Forms(strFormName).Controls(strControlName).Tag = "Foo"

or the procedure's argument could be declared as Control:

Sub MyProcedure (ctrl As Control)

and you can pass a reference to the control to it:

MyProcedure ctrl

and the code in the procedure would be something like:

ctrl.Tag = "Bar"

The names of the variables passed into the procedure don't have to be the
same as the names of the arguments.

Ken Sheridan
Stafford, England
Apparently my comm is bad. Let me put like this. In a module one can
change
an objects property with this syntax,
Forms![FlatFileData].[lblSort].Caption = "Caption here"
The form name is "FlatFileData"
The label is name "lblSort"
Hopefully no arguments with that.
OK, now what I want to do is pass the object (in this case lblSort) to
that
line of code. I assuming that it can't be done and I found another way to
accomplish the same thing.
Let me break this down further. As an on click event on any object, I want
to call this line of code passing that objects name. In doing this I can
change any objects property without writing code for each object.
To pass the Tag property to a message box:, assuming the Tag property is
on
the current form:
[quoted text clipped - 44 lines]
Thanks,
M
 
M

Mark

The lack of comm. is interesting here. I’m totally failing to ask a question.
My coworker got it right away without any follow-up? She knows me though!
It’s not about the type of object. It’s about syntax.
Forms![FormName]![ObjectName].[Object Property]
Without using ActiveControl (or maybe with) I simply from a Public Function
in a Module want to pass the object (control) to that function and modify
that objects properties. So, let me try this again. What I want to pass is
“txtTextBox†to this function and make it visible. In the syntax provided how
would I use this passed object; Forms![FormName]![txtTextBox].Visible = True
It’s the “txtTextBox†that I’m having problems deciding how it should look
in the given syntax. My solution was to avoid this entirely and use the forms
controls and loop through them until the appropriate tag was identified. With
the control identified, I could use the syntax
Forms![FormName]![txtTextBox].Visible = True This is a bit obscure here and
I apologize. It’s about getting the txtTextBox into
Forms![FormName]![txtTextBox].Visible = True syntax when it’s passed,
however it’s passed.
Thanks for your efforts. Anyone crawling around inside my mind should be
greatly rewarded and cautioned as well. One might not make the return trip
unscathed.
M
 
J

John W. Vinson

Without using ActiveControl (or maybe with) I simply from a Public Function
in a Module want to pass the object (control) to that function and modify
that objects properties. So, let me try this again. What I want to pass is
“txtTextBox” to this function and make it visible. In the syntax provided how
would I use this passed object; Forms![FormName]![txtTextBox].Visible = True
It’s the “txtTextBox” that I’m having problems deciding how it should look
in the given syntax.

Forms!FormName.Controls("txtTextBox").Visible = True

or with a string variable txtControlName

Forms!FormName.Controls(txtControlName).Visible = True
 
M

Mark

Thanks,
The following worked:
Public Function abc(MasterForm As Form, FrmObject As String)
Forms![FlatFileData].Controls(FrmObject).Visible = True
End Function

John W. Vinson said:
Without using ActiveControl (or maybe with) I simply from a Public Function
in a Module want to pass the object (control) to that function and modify
that objects properties. So, let me try this again. What I want to pass is
“txtTextBox†to this function and make it visible. In the syntax provided how
would I use this passed object; Forms![FormName]![txtTextBox].Visible = True
It’s the “txtTextBox†that I’m having problems deciding how it should look
in the given syntax.

Forms!FormName.Controls("txtTextBox").Visible = True

or with a string variable txtControlName

Forms!FormName.Controls(txtControlName).Visible = True
 
K

kate

"John W. Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> a écrit dans le
message de groupe de discussion :
(e-mail address removed)...
Apparently my comm is bad. Let me put like this. In a module one can
change
an objects property with this syntax,
Forms![FlatFileData].[lblSort].Caption = "Caption here"
The form name is "FlatFileData"
The label is name "lblSort"
Hopefully no arguments with that.
OK, now what I want to do is pass the object (in this case lblSort) to
that
line of code. I assuming that it can't be done and I found another way to
accomplish the same thing.

The form's Controls collection can be used in this way:

Forms![FlatFileData].Controls("lblSort").Caption =

In place of "lblSort" you can use a string variable or another form object
reference, just so long as it returns the name property of the desired
control.
 
K

kate

KenSheridan via AccessMonster.com said:
You can use a form's ActiveControl property to identify the current
control.
But if you wish to call a procedure from any form you'd also need to
include
an argument to accept the form's name if you use one which accepts the
name
of the control, both declared as String. Then you can them pass them like
so:


Dim ctrl as Control
Dim strFormName as String
Dim strControlName As String

Set ctrl = Me.ActiveControl
strControlName = ctrl.Name
strFormName = Me.Name

MyProcedure strFormName, strControlName

in which case the procedure would be declared like this:

Sub MyProcedure (strFormName As String, strControlName As String)

and the code in the procedure would be something like:

Forms(strFormName).Controls(strControlName).Tag = "Foo"

or the procedure's argument could be declared as Control:

Sub MyProcedure (ctrl As Control)

and you can pass a reference to the control to it:

MyProcedure ctrl

and the code in the procedure would be something like:

ctrl.Tag = "Bar"

The names of the variables passed into the procedure don't have to be the
same as the names of the arguments.

Ken Sheridan
Stafford, England
Apparently my comm is bad. Let me put like this. In a module one can
change
an objects property with this syntax,
Forms![FlatFileData].[lblSort].Caption = “Caption hereâ€
The form name is “FlatFileDataâ€
The label is name “lblSortâ€
Hopefully no arguments with that.
OK, now what I want to do is pass the object (in this case lblSort) to
that
line of code. I assuming that it can’t be done and I found another way to
accomplish the same thing.
Let me break this down further. As an on click event on any object, I want
to call this line of code passing that objects name. In doing this I can
change any objects property without writing code for each object.
To pass the Tag property to a message box:, assuming the Tag property is
on
the current form:
[quoted text clipped - 44 lines]
Thanks,
M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top