sql >> データベース >  >> RDS >> Access

MSAccessでストアドプロシージャを実行するときにこの一般的なエラーを回避する

    MSAccessでストアドプロシージャを実行するときにこの一般的なエラーを回避する

    VBAコードからストアドプロシージャを実行するのが大好きですが、注意が必要な問題が1つあります。それは、フォームに既に読み込まれているデータに影響を与えるプロシージャを実行することです。注意しないと、次のメッセージが表示されます。

    幸い、これは簡単な修正です。いくつかの提案があります:

    • フォームを閉じてから、ストアドプロシージャを実行します。これは、変更されたデータを同じフォームで確認したくない場合があることを前提としています。
    • フォームのレコードソースを何も設定せずに、元のデータソースに戻します(以下のコードを参照)。

    フォームを閉じてから、ストアドプロシージャを実行します

    開始するための疑似コードは次のとおりです。

    Private Sub RunSomeProcedure()
    Dim lngOrderID as Long
    
    'Assuming you need to pass information from your form to the stored procedure, for example, an OrderID
    lngOrderID = Me.OrderID 'If you don't store the info it will not be available after closing the form
    
    DoCmd.Close acForm, Me.Name 'This closes the form
    ExecuteMyCommand "uspStoredProcedureName " & lngOrderID
    
    End Sub

    ExecuteMyCommandに精通していませんか?ここで調べることができます。

    フォームのレコードソースをnullに設定

    Private Sub RunSomeProcedure()
    Dim lngOrderID as Long
    Dim strRecordSource as String
    
    'Assuming you need to pass information from your form to the stored procedure, for example, an OrderID
    lngOrderID = Me.OrderID 'If you don't store the info it will not be available after closing the form
    
    strRecordSource = Me.RecordSource 'Store the recordsource for later use
    Me.RecordSource = vbNullString
    ExecuteMyCommand "uspStoredProcedureName " & lngOrderID
    Me.RecordSource = strRecordSource 'Restore the form so that the user can see the updated data
    
    End Sub

    3月9日に特別ゲストのEboQuansahと一緒に参加してください!

    Accessグループの製品マネージャーであるEboを使用して、MicrosoftAccessの最新情報をご覧ください。詳細については、ここをクリックしてください:https://accessusergroups.org/sql-server-with-access/event/sql-server-with-access-whats-new-in-access-a-presentation-by-the-access- product-manager /


    1. PostgreSQLで配列の要素のインデックスを作成するにはどうすればよいですか?

    2. oraclesqlの動的ピボット-手順

    3. Oracleデータベースで例外変数を使用してユーザー定義の例外を宣言する方法

    4. Oracle INTERVAL DAYTOSECONDデータ型のNHibernateマッピング