0

I am trying to get the last added Record Id but cant seem to get the recordset to load. I keep on getting "Runtime Error 3219 Invalid Operation". What am I doing wrong?

        Dim db As DAO.Database
        Dim qry As DAO.QueryDef
        Dim rs As DAO.Recordset

        Set db = CurrentDb
        Set qry = db.QueryDefs("AASourceApp")

        'qry.Parameters.Refresh
        qry.Parameters("[Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![cmbUpgradeTo]") = [Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![cmbUpgradeTo]
        qry.Parameters("[Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![SourceID]") = [Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![SourceID]
        'qry.Execute  'if unquoted qry.execute works without a problem

        'Determine newly created record id
        Set rs = qry.OpenRecordset()   ''''''ERROR - Invalid Operation''''''
        Debug.Print rs.LastModified

        rs.Close
        Set rs = Nothing
        Set db = Nothing

Here is the stored SQL for the AASourceApp query:

PARAMETERS [Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![SourceID] Long, [Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![cmbUpgradeTo] Short;
    INSERT INTO [SourcDoc Tbl] ( [SourceID Link], [SubAccount ID], SourcTypeID, SDate )
    SELECT [SourcDoc Tbl].SourceID, [SourcDoc Tbl].[SubAccount ID], [Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![cmbUpgradeTo] AS DocType, Date() AS Date1
    FROM [SourcDoc Tbl]
    WHERE ((([SourcDoc Tbl].SourceID)=[Forms]![AAAccounts Form]![AASourcDoc Subform].[Form]![SourceID]));
HansUp
  • 95,961
  • 11
  • 77
  • 135
Rhdr
  • 387
  • 4
  • 22
  • It shouldnt return any data though. You need a query after to get the latest, i dont think you can do this way. – Nathan_Sav Feb 03 '16 at 13:55

1 Answers1

0

It shouldnt return any data though. You need a query after to get the latest, i dont think you can do this way. Perhaps a select with the same criteria and parameters?

Nathan_Sav
  • 8,466
  • 2
  • 13
  • 20