Hide Current form then open new

A

acss

I have a command button on my form that i am trying to hide the current form
Orders then open form Orders2:

Private Sub cmd_OpenForm()
Me.Visible = False
DoCmd.OpenForm "Orders2", , , , , acDialog
Me.Visible = True
End Sub

The orders2 form is a copy of Orders with a default value in a country field
set to EC and the code above does not perform the closing of one and opening
of the other. Can someone assit please?
 
J

Jeanette Cunningham

Private Sub cmd_OpenForm()
DoCmd.OpenForm "Orders2", , , , , acDialog
End Sub

On the load event for Orders2, put code to hide the form Orders
Forms!frmOrders.Visible = False



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
A

acss

Thanks Jeanette that did the trick. Is it possible to have the Orders2 form
open on last record of form Orders since one really is a copy of the other
and will only open on first record selector. For example if Orders last
record is #11 i would like Orders2 to open on record #12. Can this be done?

Thanks for the support
 
J

Jeanette Cunningham

You can use a where clause to open a form at a particular record.

The code below will open Orders2 at the same record that is selected on
Orders.
Private Sub cmd_OpenForm()
Dim strWhere as String
strWhere = "[PKeyField] = " & Me.[PKeyFieldControlName]
DoCmd.OpenForm "Orders2", , , strWhere, , acDialog
End Sub

If PKeyField is a text data type, use
strWhere = "[PKeyField] = """ & Me.[PKeyFieldControlName] & """"

Replace PKeyField and PKeyFieldControlName with the primary key field for
your Orders form.

If you want to open at the next record, you could if you could supply the
Primary key value for the next record. I'm not sure how you would know that
in this situation.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

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