Saving record before linking two forms

dealwi8me

Registered User.
Local time
Tomorrow, 01:03
Joined
Jan 5, 2005
Messages
187
I have a command button that connects two forms. I need to save form1 before opening form2. I added a line for saving the record and then open form2 as following but it doesn't work.

Any suggestions?

Code:
Private Sub Command30_Click()
On Error GoTo Err_Command30_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    'Saving record
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    stDocName = "form2"

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

Exit_Command30_Click:
    Exit Sub

Err_Command30_Click:
    MsgBox Err.Description
    Resume Exit_Command30_Click
    
End Sub

Thank you in advance.
 
because i checked the table of form1 after form2 was opened and the record wasn't inserted.
 
Maybe there is nothing to save. Replace:
Code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
...with:
Code:
If Me.Dirty Then
   MsgBox "Saving record"
   Me.Dirty = False
Else
   MsgBox "Nothing to save"
End If
 
Allan's suggextion is an excellent one! You do understand, though, that looking in the table for a record doesn't mean looking in the A's for a client named Adams? There's no particular order in a table, it's just a jumble of data.
 
I just realised i was doing something really stupid! I added the code line for saving the record in the wrong command button.:mad:

The code is working just fine, I apologise for wasting your time :(
 
I just realised i was doing something really stupid! I added the code line for saving the record in the wrong command button.:mad:

The code is working just fine, I apologise for wasting your time :(

Good to hear, but you should still really replace:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

with:
DoCmd.RunCommand acCmdSaveRecord

the DoMenuItem code is something that has really been obsolete since Access 2000 and it is stated that it is only there for backwards compatibility (although it really shouldn't be available at this point, but MS hasn't removed it yet).
 
Not only hasn't removed, but still continue to use it thru the Command Button Wizard in ACC 2003! I do believe, though, that I've heard that they've started to replace some of this code in 2007!
 
Not only hasn't removed, but still continue to use it thru the Command Button Wizard in ACC 2003! I do believe, though, that I've heard that they've started to replace some of this code in 2007!

Yeah, their wizard code doesn't reflect best practices for most of it. I think they just didn't have this as too high on the list of things to fix since it would work, even though it wasn't really technically correct, or fit into their official statements.
 
Oh, i didn't know that, i just used the wizard.

Thanks for the info, i will replace it!
 

Users who are viewing this thread

Back
Top Bottom