How to Open linked form and close existing form?

D

DMarieD

Hi

I have 2 forms linked to the same table but they show different fields. I
added a button to each to flip flop between views but if the first form
doesn't close I get an error that the record cannot be updated and a few
records have gotten corrupt because of this.

How can I code for the button to link to the same record in another form AND
CLOSE THE EXISTING FORM once the new form is opened?

Table: VENDOR SETUP TABLE
Form 1: VENDOR SETUP FORM New
Form 2: VM NOTES

Thanks.
DD
 
J

John Spencer

Instead of two forms, why don't you just use a tab control with two tabs on
the one form. That would seem to make more sense.

IF you really have to do this by closing and opening forms then you need to
pass the form you are opening information to let it open to the required
record. One method would be as follows. UNTESTED, GENERIC SAMPLE CODE
follows.

Private Sub SomeButton_Click()
Dim vPrimaryKey as Long

vPrimaryKey = Me.PrimaryKeyValue

IF Me.Dirty = True then Me.Dirty = False 'Save any change
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "VM Notes", WhereCondition:= "PrimaryKey=" & vPrimaryKey

End Sub


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Top