Open Last Form

M

mem

I want to add a button to my form. I want one to close the form and open the
main form, simple enough. The other button I want to open the form they
filtered the information on. Otherwise go to last page. There are different
forms that will filter to this form, that is why I want it to go back to the
original form it was filtered from. Is there a way to do this? Thanks!
 
D

Dale Fye

You could pass the name of the form that opened this form as an OpenArg of
the OpenForm method. I assume that when you click the "Previous Form"
button, you are actually closing the current form. The code in that click
event might look like:

Private Sub cmd_PreviousForm_Click

dim strFormName as string

if LEN(me.OpenArgs & "") = 0 then
strFormName = "frm_Main"
else
strFormName = me.openargs
endif

if currentproject.allforms(strFormName).isloaded then
forms(strFormName).visible = true
Else
Docmd.Openform strFormName
Endif

docmd.close acform, me.name

End sub

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
M

mem

Ok I have tried this. Now my problem is that the OpenArgs is coming up as
NULL. All it does is open my main form and not the previos form.
 
D

Dale Fye

When you open the form, you have to pass it an argument. This is the last
argument of the OpenForms method. Look at the code that is opening the new
form. The last item in that list is optional, and not normally included, but
the command might look like:

docmd.OpenForm "formname",,,,,acDialog, me.name

you will find this command on each of the forms that calls this new form.
--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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