How to 'force' new form to 'Add" itself before closing it ?

M

Mel

I have

tblAccounts
tblPeople

frmAccounts
frmPeople

On frmAccounts I have a Command Button "Add People" which opens
frmPeople so we can add contacts to the account.

BUT... when we create a NEW "Account" record and immideately "Add" a
contact... the new person doesn't get added.

We must create the Account record...
then backup a record and return to the record
before we can successfully add people/contacts to the account.

My questions...
1 - What code would I add to the "Add People" button on frmAccount to
force Access to add the new account record?

2 - And how do I have the code not execute if the record has already
been added?

thanks for any help.

Mel
 
J

John W. Vinson

I have

tblAccounts
tblPeople

frmAccounts
frmPeople

On frmAccounts I have a Command Button "Add People" which opens
frmPeople so we can add contacts to the account.

BUT... when we create a NEW "Account" record and immideately "Add" a
contact... the new person doesn't get added.

We must create the Account record...
then backup a record and return to the record
before we can successfully add people/contacts to the account.

My questions...
1 - What code would I add to the "Add People" button on frmAccount to
force Access to add the new account record?

2 - And how do I have the code not execute if the record has already
been added?

You can save yourself a lot of trouble by simply putting frmPeople onto
frmAccounts as a Subform. That will automatically maintain the link between
the two forms, requires no code, and will prevent this problem.

Is that feasible? Or do you really need the separate "popup" form? If so, put
a line in the Add People command button's code like

If Me.Dirty Then Me.Dirty = False

which will force a save of the record. You should probably also pass the
Account table's Primary Key to frmPeople so that you can ensure the link.

But... the Subform, as I say, does all this for you.

John W. Vinson [MVP]
 
M

Mel

Problem is no screen space left for another subForm... as we already
have two subForms on the Main Form.

Can you share a code snippit to pass the Account table's Primary Key
to frmPeople or does my stLinkCriteria line take care of this?

Here is what I have now...

If Me.Dirty then Me.Dirty = False ' line you suggested

Dim stDocName As String ' code as it was before your line
Dim stLinkCriteria As String
stDocName = "frmAcctPeople"
stLinkCriteria = "[idAcct]=" & Me![idAcct]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Thanks for the help.

Mel
 
M

Mel

EUREKA !!!!!!!

Didn't know you could do that !!!

A quick Google showed me how... and...

The darn thing is right there on the tool bar... duh!

Funny how one can start using a tool and never really learn all the
basic capibilities.

Thanks Rick

Mel
 
R

Rick Brandt

John said:
<g> Brevity is the soul of wit... and in this case, of good technical
advice!

John W. Vinson [MVP]

I think I just used up all of my keystroke allowance on the Upsize to SQL Server
thread :)
 

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