Using SetValue in sub-form macro

  • Thread starter SimonG via AccessMonster.com
  • Start date
S

SimonG via AccessMonster.com

I have a button on a sub-form which resets three user controls on that sub-
form.
I would like the sub-form to be generic, so that I can use it with more than
one parent.

Currently the button runs a macro:

Action: SetValue
Item: [myFormName]![txtOption1]
Expression: “â€
Action: SetValue
Item: [myFormName]![txtOption2]
Expression: “â€
Action: SetValue
Item: [myFormName]![txtOption2]
Expression: “â€

{This is taken from the form, originally written as a parent, and works as
required.}

To convert this form to a generic sub-form (the fully qualified from name
will change for each parent the sub-form is used in). I have tried changing
the macro as follows:

Action: SetValue
Item: [me].[txtOption1]
Expression: “â€
Action: SetValue
Item: [me].[txtOption2]
Expression: “â€
Action: SetValue
Item: [me].[txtOption2]
Expression: “â€

Whilst this does not give an error message, it does not reset the option
boxes for the user.
How do I need to change the macro, so that the button works as required?
 
S

Steve Schapel

Simon,

You might need to explain a bit more. It is hard to understand what
[myFormName] refers to. If the button is on the subform, as you state,
and the controls are also on the subform, then the Item argument of the
SetValue just needs to show the name of the control. For example...
Item: [txtOption1]

If the button is on the subform, and the controls are on the main form,
then you can refer to the Parent, for example:
Item: [Parent]![txtOption1]

If the button is on the main form, and the controls are on the subform,
then this is the type of syntax you currently are using.
Item: [NameOfSubformControl]![txtOption1]
.... but, if that's the scenario, I can't see what you mean about making
it generic.

By the way, are you sure you want to set the value of the control to a
zero-length string ""? This is a bit irregular. Normally I would
expect to see the Expression argument say: Null
 
S

SimonG via AccessMonster.com

Hi Steve,

Thanks for the reply.

[myFormName] is the name of the form.

I've found out the hard way (by trying) that SetValue doesn't work with just
the control name, for example:
Item: [txtOption1]
and to get it to work I have to include the form name to set a value, eg:
Item: [myFormName]![txtOption1]

What I mean by making the sub-form “genericâ€, is that I would like to be able
to include the same sub-form in different parent forms.
Hence my problem: if to use SetValue I need to include the form name, the
full form name* will change depending on which parent form the sub-form is
included in. How do I allow for this?

* assuming the naming format must conform to:
Forms!MainFormName.SubformContainerName.Form
and
Forms!MainFormName.SubformContainerName.Form!ControlName

Many thanks,
Simon


PS
The zero string “â€, is something I've picked up from posted code samples I've
seen, I've tended to adopt it as it has the advantage that I don't have to
deal with Nulls (also from years ago I've had it drummed into me to declare
and assign). I guess its just what I'm used to...

Steve said:
Simon,

You might need to explain a bit more. It is hard to understand what
[myFormName] refers to. If the button is on the subform, as you state,
and the controls are also on the subform, then the Item argument of the
SetValue just needs to show the name of the control. For example...
Item: [txtOption1]

If the button is on the subform, and the controls are on the main form,
then you can refer to the Parent, for example:
Item: [Parent]![txtOption1]

If the button is on the main form, and the controls are on the subform,
then this is the type of syntax you currently are using.
Item: [NameOfSubformControl]![txtOption1]
... but, if that's the scenario, I can't see what you mean about making
it generic.

By the way, are you sure you want to set the value of the control to a
zero-length string ""? This is a bit irregular. Normally I would
expect to see the Expression argument say: Null
I have a button on a sub-form which resets three user controls on that sub-
form.
[quoted text clipped - 33 lines]
boxes for the user.
How do I need to change the macro, so that the button works as required?
 
S

Steve Schapel

Simon,

Sorry, Mate, I'll try again...

Is the button on the main form or the subform?

Are the controls on the main form or the subform?

What is the name of the main form?

What is the name of the subform?

Thanks.
 
S

SimonG via AccessMonster.com

Hi Steve,

Sorry, guess we were at crossed purposes.

My form is currently a stand alone (or a parent with no child), originally
built as a proof of concept. I am now trying to use this proven form as a
sub-form in other forms.
Answering your questions with how I want things working when completed:

What is the name of the main form?
f_OrderEntry
f_StockMaint
What is the name of the subform?
f_StockSelect
Is the button on the main form or the subform?
sub-form (f_StockSelect)
Are the controls on the main form or the subform?
Sub-form (f_StockSelect)

Some background to the controls:
the controls and button are aligned in a single row at the top of the sub-
form;
the controls allow the user to enter features for searching (filtering) the
product list;
the button clears any search criteria entered into the controls.

Hope this clarifies things,
Thanks,
Simon

Steve said:
Simon,

Sorry, Mate, I'll try again...

Is the button on the main form or the subform?

Are the controls on the main form or the subform?

What is the name of the main form?

What is the name of the subform?

Thanks.
Hi Steve,
[quoted text clipped - 21 lines]
Many thanks,
Simon
 
S

Steve Schapel

Simon,

Thanks for the further explanation.

If the button and criteria controls are in the Header section of the
f_StockSelect form, then the macro running on the button will be
independent of whether the form is stand-alone, or embedded as a
subform. If it's a subform, you don't need to refer to the main form,
so should work whichever main form the subform is on. The syntax of the
macro will be:

Action: SetValue
Item: [txtOption1]
Expression: Null
Action: SetValue
Item: [txtOption2]
Expression: Null
Action: SetValue
Item: [txtOption3]
Expression: Null

I know that you stated earlier that "SetValue doesn't work with just the
control name", but this is incorrect.
 

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