Which form opened this report?

  • Thread starter Thread starter CyberDwarf
  • Start date Start date
C

CyberDwarf

Hi,

Being very dumb today!

I need to know, in VBA code, which form was used to call a report (using
DoCmd.OpenReport). The OpenArgs property is already in use for other
purposes.....

Must be some sort of method or property to do this???

Can anyone help?

TIA

Steve
 
you could write the form name to a global variable in the procedure that
calls the OpenReport action, and either use the variable directly, or store
the variable's value in the report's Tag property in the report's Open event
procedure, and use it from there.

hth
 
There's nothing built into Access.

You could concatenate two things into the OpenArgs property when you open
the report, and then split the property into its parts in the report.
 
Well, actually, how have you for years picked what form called another form?

You don't need to pass openargs, and FOR SURE you don't want to use global
vars as suggested (that just makes for buggy code..and what happens if you
need two forms open!!!).

You can pick up the previous forms name in the on-open event of a form, and
EVEN AS LATE AS THE ON-LOAD event....

Until those events actually finish, the form is not yet loaded.


So, lot of my code has a form module level garble called

frmPrevious


So, in my on-open event of the form I go:


set frmPrevious = screen.Activeform


Now, anywhere in that forms code, I h ave a ready made reference to the
previous calling form

msgbox "name of called form is " & frmPrevous.Name

Or, to requery he calling form

frmPrevious.Requery

So, as a coding standard, I have a ready made "feature" that gives me
complete use of the calling form.....

However, this wonderful suggestion DOES NOT work for reports..and if your
report is opened in NON preview mode, then you can't use screen.ActiveForm
in the reports on-open event as above.

So, at this point, I think I would actually use open args...and pass two
values....


dim strArges as string

strArges = me!CustomerID & "~" & me.name

docmd.OpenReport "MyReport",acViewPreview,,,,strArgs

Then, in your reports on open, you go:

lngCustoerID = split(me.openArgs,"~")(0)
strFormPrevous = split(me.OpenArgs,"~")(1)

frmPrevous = forms(strFromPrevous)


So, I just split out the prams passed...and as above...I *still* get my nice
frmPrevous that all reports, forms have in code now!!!

Hence

frmPrevious!LastName = "kallal"
frmPrevous.MyCustomPrint

So, we still have a full reference variable to the previous "calling" form
in the report that we can requery, or run code, or do whatever we want with
that "prevous" form....
 
you're welcome, Steve; make sure you read Albert's comments in this thread
re using a global variable, though.
 

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

Back
Top