Solved TempVars and Form Events (1 Viewer)

Sarah.M

Member
Local time
Today, 02:23
Joined
Oct 28, 2021
Messages
300
Hi, Plz note, My VBA is blocked by IT for security reason.
I can use only Expression builder, Macros, Queries, Tables, Forms and Reports only.
------------------------------------------------
Hi, on this example I want to understand the concept of TempVars and Form Events
dose macro can do what in the attached picture below, and then embedded that macro to on open event of AddNewMeetingF? :unsure:
on Add mode there is steps, if it is Edit no steps
it is not necessary to be in Submacro, I am just trying to solve my question, mybe IfElse is working not sure
Plz help me 🙏

Sample attached

1647285455248.png
 

Attachments

  • 19.accdb
    1.1 MB · Views: 134

Sarah.M

Member
Local time
Today, 02:23
Joined
Oct 28, 2021
Messages
300
I tried this way but still not working
plz help 🙏

Sample attached

1647297152664.png
 

Attachments

  • 20.accdb
    1.1 MB · Views: 108

Sarah.M

Member
Local time
Today, 02:23
Joined
Oct 28, 2021
Messages
300
plz help
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:23
Joined
Feb 28, 2001
Messages
22,778
This reference suggests that there is a SetTempVars macro that you could use, which implies that you CAN use TempVars in a macro. Also RemoveTempVars and RemoveAllTempVars, so I would suggest it is likely that they are supported.


EDIT: This reference explicitly suggests that you can use TempVars in a macro.


Having not ever done this myself, all I can do is suggest it is possible.

One last edit:


There is a segment of code in that pages that uses the value from a TempVars object.
 

GPGeorge

Grover Park George
Local time
Yesterday, 16:23
Joined
Nov 25, 2004
Messages
663
Can you help us locate the problem by identifying where the macro is located? Call me lazy, but I hesitate to wander through four different forms looking for things.
 

strive4peace

AWF VIP
Local time
Yesterday, 18:23
Joined
Apr 3, 2020
Messages
856
hi @Sarah.M

You're trying to use one macro to respond to several events, and use IF statements to see which one event called it ... AfterInsert is an event, not a variable you can use -- same with the others. Set a temporary variable if you want to do it that way.

Each of those events would need to call the macro -- you can't put it on the form open event and expect to define all those behaviors.

btw, the Open event can cancel opening the form because it isn't LOADed yet. Therefore, you can't set or get any information from the form.
 
Last edited:

GPGeorge

Grover Park George
Local time
Yesterday, 16:23
Joined
Nov 25, 2004
Messages
663
Also, it would help if you explain where that tempvar's value is set.
 

GPGeorge

Grover Park George
Local time
Yesterday, 16:23
Joined
Nov 25, 2004
Messages
663
BTW: Out of curiosity.

Although you insist that VBA is disabled for you, the AddNewMeeting form DOES have VBA in it. Does that mean you wrote the VBA but that it doesn't actually execute? Or is this taken from another accdb that you obtained, perhaps as a template?
1647370470566.png
 

strive4peace

AWF VIP
Local time
Yesterday, 18:23
Joined
Apr 3, 2020
Messages
856
ps, @GPGeorge, on the click event of the button that opens the form:

tvarOpenMode = "Add"

---
good question -- oops, sorry! Yes! ... just that since I took the time to look and figure it out, thought I'd share ...
 
Last edited:

GPGeorge

Grover Park George
Local time
Yesterday, 16:23
Joined
Nov 25, 2004
Messages
663
ps, @GPGeorge, on the click event of the button that opens the form:

tvarOpenMode = Add"

---
good question -- oops, sorry! Yes! ... just that since I took the time to look and figure it out, thought I'd share ...
Your analysis is right, of course. The macro as written is trying to evaluate an event, which isn't valid in this context.
 

strive4peace

AWF VIP
Local time
Yesterday, 18:23
Joined
Apr 3, 2020
Messages
856
@Sarah.M, to decipher the error messages ...

The first message:
1647372602265.png

doesn't really tell you what's wrong ... mainly that it's something involving "AfterInsert"

the second error:
1647372661775.png


tells you where problem is ... the Open event of the AddNewMeeting form. It's not the ONLY problem ...

Although the expression builder lets you choose events, you cannot evaluate them like variables. @GPGeorge said it better, "The macro as written is trying to evaluate an event, which isn't valid in this context."

Then, after that, there is yet another error:
1647372863841.png


this happened because the form the macro called to open failed to do so.

btw, before assigning a button to do something, it's a good idea to change the NAME property from an auto-generated name like Command23 to something more descriptive like cmd_Open_AddNewMeeting ~ this makes is easier to see what's going on, especially down the road.

The Name property is the first one listed on the Property Sheet for a control on the the Other and All tabs
 

Attachments

  • 1647372847535.png
    1647372847535.png
    6.4 KB · Views: 125
Last edited:

Sarah.M

Member
Local time
Today, 02:23
Joined
Oct 28, 2021
Messages
300
Can you help us locate the problem by identifying where the macro is located? Call me lazy, but I hesitate to wander through four different forms looking for things.
Thanks for replying
in post #2 attachment TempVars located in AllMeetingsF and AddnNewMeeting on open event

1647409257736.png

1647409323588.png
 

Sarah.M

Member
Local time
Today, 02:23
Joined
Oct 28, 2021
Messages
300
Although the expression builder lets you choose events, you cannot evaluate them like variables. @GPGeorge said it better, "The macro as written is trying to evaluate an event, which isn't valid in this context."

this happened because the form the macro called to open failed to do so.

btw, before assigning a button to do something, it's a good idea to change the NAME property from an auto-generated name like Command23 to something more descriptive like cmd_Open_AddNewMeeting ~ this makes is easier to see what's going on, especially down the road.

The Name property is the first one listed on the Property Sheet for a control on the the Other and All tabs
Thanks for replying,
Thanks for the clarification
 

Sarah.M

Member
Local time
Today, 02:23
Joined
Oct 28, 2021
Messages
300
BTW: Out of curiosity.

Although you insist that VBA is disabled for you, the AddNewMeeting form DOES have VBA in it. Does that mean you wrote the VBA but that it doesn't actually execute? Or is this taken from another accdb that you obtained, perhaps as a template? View attachment 99164
He convert it to Macro to me
 

strive4peace

AWF VIP
Local time
Yesterday, 18:23
Joined
Apr 3, 2020
Messages
856
@Sarah.M, to make it easy on yourself, create separate macros for the different events. Then call those macros from their respective events.
  1. toggle display of the Properties window in the design view of the form: Alt-Enter
  2. select the form object (click in upper left where rulers intersect), then choose the Events tab in the Properties window
  3. click in each event where you want something to happen, and specify the proper macro
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:23
Joined
May 7, 2009
Messages
16,393
you just use the "form's" event to capture the value of [TempVars]![tvarOpenMode]
rather than do it on "separate" macro.
 

Attachments

  • 19.accdb
    776 KB · Views: 130

Users who are viewing this thread

Top Bottom