Forms: Buttons to open other forms and close button

V

Veli Izzet

Hi all,

I have a form frmForm2 that I open either from another form(s) or directly,

1-I want to put a close button, that

checks from where the frmForm2 is opened (which other form, or direct)
goes to that form, does a requery action on that form (or all comboboxes
on that form), and closes itself.

2- When calling frmForm2 from frmForm1 is it a good practice use

if me.dirty=true then me.dirty=false in the code before opening the frmForm2

Thanks for answers.
 
G

Guest

u can use the OpenArgs properties in OpenForm Method

e.g. Docmd.OpenForm , Form1, , , , "ByForm2"

then in Form1 OnOpen event:
Select Case Me.OpenArgs
Case "ByForm2"
do your code
Case "ByForm3"
do your code
End Select



"Veli Izzet" 來函:
 
V

Veli Izzet

Thanks,

In the code, when I close Form1 to get back, do I first close Form1 and
go back to Form2, or do I go back to Form2 and then close Form1.

Can you please help me with this issue too if you may..
 
A

Albert D.Kallal

Veli Izzet said:
Hi all,

I have a form frmForm2 that I open either from another form(s) or
directly,

1-I want to put a close button, that

checks from where the frmForm2 is opened (which other form, or direct)
goes to that form, does a requery action on that form (or all comboboxes
on that form), and closes itself.

Ok, you can pick up the calling form name in the on-open, and EVEN as late
as the on-load.

We have to assume that frm2 is thus opened by another form (you should not
be letting uses click on a form in the forms tab anyway).

So, in the forms module, you can use

dim frmPrevious as form

Now, in the forms on-load event, we can go:

set frmPrevious = screen.ActiveForm

Now, to requery the previous form, we can go

frmPrevious.Requery

If no other forms are going to be opened, then opening frm2 would fail since
there is no previous form. (if this is what you mean by direct), Then we
need a different approach. You will have to *pass* the name of the calling
form. You can use:

form1:

buttion code to open form 2 could be
docmd.OpenForm "form2",,,,,,"form1"


In form 2, in the open args command will give us the name of what we passed

So, when we close, or want to check the calling form, we use

if isnull(me.openargs) = false then

forms(me.OpenArgs).Requery
end if

If openargs is blank...then no called form..and we assume it was opened
direct...
2- When calling frmForm2 from frmForm1 is it a good practice use

if me.dirty=true then me.dirty=false in the code before opening the
frmForm2

Yes, the above is not a bad idea. In fact, it is critical that you do so if
both forms work on the same table (this means that form2 should be model in
this case also, since we have TWO forms hitting the same table (and often he
same record!)). If the forms are to be used for different tables, then
saving is not critical, but in most cases when one form loads another (and
so on), usually there is some reasons of needing to ensure that data from
the previous form is written to disk (this is not always the case, but often
it is). If you save the data, then those additional forms can use the table
data, and not have to ref the form to get those values (that are not yet
saved). And, for things like sub-totals, then again having things written to
disk tends to help also.
 

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