Save related record when opening separate form

  • Thread starter ThomasK via AccessMonster.com
  • Start date
T

ThomasK via AccessMonster.com

I have a form where I enter address records. Its based on the table
"Addresses". It has a comand button which opens another form based on a
related table (occupancy). The problem that Im having is that after I enter a
record in the address form and click the comand button to open the other form
an error message comes up stating that I must first save the record in the
related (address) table. If I go to the menu and select Save Record before I
hit the comand button to open the form the error does not come up. This is
what I have on the comand button code.....

Private Sub cmdOpenOccupancy_Click()
On Error GoTo Err_cmdOpenOccupancy_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmOccupancy"

stLinkCriteria = "[AddressID]=" & Me![AddressID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenOccupancy_Click:
Exit Sub

Err_cmdOpenOccupancy_Click:
MsgBox Err.Description
Resume Exit_cmdOpenOccupancy_Click

End Sub

Is there some way to add a save or something so that the address record saves
when I click the comand button? The address form stays open after the
occupancy form is opened.

Thanks
 
C

Craig

A single line of code should do the trick:
"DoCmd.RunCommand acCmdSaveRecord"
Do this before anything else.
 
T

ThomasK via AccessMonster.com

I added it like this, and it worked great!!

Private Sub cmdOpenOccupancy_Click()
On Error GoTo Err_cmdOpenOccupancy_Click

DoCmd.RunCommand acCmdSaveRecord

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmOccupancy"

stLinkCriteria = "[AddressID]=" & Me![AddressID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenOccupancy_Click:
Exit Sub

Err_cmdOpenOccupancy_Click:
MsgBox Err.Description
Resume Exit_cmdOpenOccupancy_Click

End Sub

Thank you very very much.

Tom
A single line of code should do the trick:
"DoCmd.RunCommand acCmdSaveRecord"
Do this before anything else.
I have a form where I enter address records. Its based on the table
"Addresses". It has a comand button which opens another form based on a
[quoted text clipped - 30 lines]
 

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