Referencing forms and fields

  • Thread starter Thread starter Daniel Jacobs
  • Start date Start date
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.
 
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])
 
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.


.
 
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.


.
 
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.


.


.
 
Back
Top