0
votes

I'm trying to achieve this in Access 2016 purely using macro code, without vba.

I have a form frmMaintenance that lists jobs. New jobs are added to the jobs table tblJob via the form frmAddJob.

frmAddJob is displayed, when a button is clicked on frmMaintenance, by an OpenForm macro. Once frmAddJob is open, I want to set a value of one of its controls, indicating job-type.

Then, after frmAddJob is closed, I want to requery the control on frmMaintenance that lists the jobs.

The macro code in my btnAddJob OnClick is, in outline, like this:

  • OpenForm //open frmAddJob
  • SetValue //of control on frmAddJob
  • Requery //the control in frmMaintenance

The problem is that if frmAddJob is opened non-modally, 'Window Mode'=Normal, the Requery is executed straight away. On the other hand, if frmAddJob is opened with 'Window Mode'=Dialog, then the macro code pauses until the window is closed, and I never get to set the required value.

The 2 solutions that occur to me are:

Set frmAddJob somehow to modal, after SetValue. However, using OpenForm 'Window Mode'=Dialog on an already open form doesn't seem to work.

Have frmAddJob get the value it needs from frmMaintenance in its 'On Open' event. However, this makes frmAddJob dependent on frmMaintenance and thus non reusable.

Is this possible just using maros?

1
Set the value in AddJob on the Open Event, but use an open args property to provide the value, if there isn't one don't set it. This will let use the Modal method correctly, and allow your form to be used elsewhere. I'm not sure if OpenArgs is available in a macro as I don't use them. What's the issue with using some VBA ? - Minty
Thanks Minty. No, I can't see any OpenArgs parameter than can be supplied to the OpenForm macro. Regarding vba, this is just a test database, I'm experimenting with what can be done purely with macros. - rgh
I'm experimenting with what can be done purely with macros. -- I don't want to be rude, but that's kinda silly and definitely a waste of time. - Andre
Thanks Andre. Well, I am indeed experimenting, knowing macros to be both limited and ugly. If what I'm trying to do just isn't sensibly possible, that would answer my question. - rgh
Could TempVars be useful here? - June7

1 Answers

0
votes

From suggestion of @June7, solution in outline is:

In frmMaintenance:

  • SetTempVar tvJobType
  • OpenForm frmAddJob modally
  • RemoveTempVar tvJobType
  • Requery

In frmAddJob:

  • in OnLoad, SetValue of required item to [TempVars]![tvJobType]
  • save the new record
  • close

Works fine and the requirement for frmAddJob to have any knowledge of from where it was opened is gone.