Referencing forms and fields

D

Daniel Jacobs

I would like to reuse macros across many forms but i do not know the syntax
that would allow me to do so. For example, I have a macro that uses setvalue
to change the value of a field if another field's value changes. The form
field reference is
[Forms]![f_events_and_shows_ds]![f_bookings_all].[Form]![entered_date_time].
I would like to invoke the same event in two forms but at present, i have to
create (and maintain) two versions of the macro.

Can you tell me what the syntax is that would allow me to replace the form
name with the current form name (say) and is there somewhere that i could go
on the web that would help me reference this area.
 
A

Arvin Meyer [MVP]

I think that you'll need to do this in code, where you can use a form name
as an argument:

Public Function DoSomething(frm As Form)

If you put the function in a standard module, you can use it just like a
macro, by setting the AfterUpdate event like:

= DoSomething([Forms]![ThisForm])
 
D

Daniel Jacobs

So there is nothing like a "currentform", "currentfield" argument available
that I could use

Arvin Meyer said:
I think that you'll need to do this in code, where you can use a form name
as an argument:

Public Function DoSomething(frm As Form)

If you put the function in a standard module, you can use it just like a
macro, by setting the AfterUpdate event like:

= DoSomething([Forms]![ThisForm])

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Daniel Jacobs said:
I would like to reuse macros across many forms but i do not know the syntax
that would allow me to do so. For example, I have a macro that uses
setvalue
to change the value of a field if another field's value changes. The form
field reference is
[Forms]![f_events_and_shows_ds]![f_bookings_all].[Form]![entered_date_time].
I would like to invoke the same event in two forms but at present, i have
to
create (and maintain) two versions of the macro.

Can you tell me what the syntax is that would allow me to replace the form
name with the current form name (say) and is there somewhere that i could
go
on the web that would help me reference this area.


.
 
A

Arvin Meyer [MVP]

Sure, you could use:

Screen.ActiveForm
and
Screen.ActiveControl

but that can be dangerous if something else gains focus.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Daniel Jacobs said:
So there is nothing like a "currentform", "currentfield" argument
available
that I could use

Arvin Meyer said:
I think that you'll need to do this in code, where you can use a form
name
as an argument:

Public Function DoSomething(frm As Form)

If you put the function in a standard module, you can use it just like a
macro, by setting the AfterUpdate event like:

= DoSomething([Forms]![ThisForm])

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Daniel Jacobs said:
I would like to reuse macros across many forms but i do not know the
syntax
that would allow me to do so. For example, I have a macro that uses
setvalue
to change the value of a field if another field's value changes. The
form
field reference is
[Forms]![f_events_and_shows_ds]![f_bookings_all].[Form]![entered_date_time].
I would like to invoke the same event in two forms but at present, i
have
to
create (and maintain) two versions of the macro.

Can you tell me what the syntax is that would allow me to replace the
form
name with the current form name (say) and is there somewhere that i
could
go
on the web that would help me reference this area.


.
 
D

Daniel Jacobs

Perfect. Thank you.

Arvin Meyer said:
Sure, you could use:

Screen.ActiveForm
and
Screen.ActiveControl

but that can be dangerous if something else gains focus.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Daniel Jacobs said:
So there is nothing like a "currentform", "currentfield" argument
available
that I could use

Arvin Meyer said:
I think that you'll need to do this in code, where you can use a form
name
as an argument:

Public Function DoSomething(frm As Form)

If you put the function in a standard module, you can use it just like a
macro, by setting the AfterUpdate event like:

= DoSomething([Forms]![ThisForm])

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


I would like to reuse macros across many forms but i do not know the
syntax
that would allow me to do so. For example, I have a macro that uses
setvalue
to change the value of a field if another field's value changes. The
form
field reference is
[Forms]![f_events_and_shows_ds]![f_bookings_all].[Form]![entered_date_time].
I would like to invoke the same event in two forms but at present, i
have
to
create (and maintain) two versions of the macro.

Can you tell me what the syntax is that would allow me to replace the
form
name with the current form name (say) and is there somewhere that i
could
go
on the web that would help me reference this area.


.


.
 

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