0

Access 2010 を使用していますが、あるテーブルのレコードを別のテーブルの情報で更新する方法を知りたいです (また、使用する他のテーブルのレコードを指定したい)。2 つのテーブル (Products と Sales) があります。私がしなければならないことは、販売フォーム (販売単位を指定) に新しい販売を登録するときに、Products テーブル内のその製品の利用可能な単位から販売単位を割引したいということです。更新クエリを使用する必要があることを読み、次のようにします。

Field: Available units
Table: Products
Update to: [Products].[Available units] - [Sales].[Sold units]

Field: Code
Table: Products
Update to: 
Criteria: [Insert code]

2 つのテーブルは Code フィールドによって関連付けられており、Code は製品テーブルの主キー フィールド (製品は 1 回だけ登録されます) であり、sales テーブルの主キー フィールドは、SaleNumber と呼ばれる自動番号付けフィールドです。1 つの製品で多くの販売が可能です。

何も見つかりません。私はAccessの初心者です。

4

1 に答える 1

0

フォームを使用していて、VBA を少し書きたい場合は、必要なものすべてを実行する送信ボタンを作成できます。次のようになります。

Private Sub Submit_Button_Click()

Dim myR as Recordset
Dim myR2 as Recordset
Dim strSQL as String

'Select the product from the table that contains the available products
strSQL = "SELECT * FROM Available_Units WHERE Products = '" & me.product_field & "'"

'Set each table accordingly
Set myR as CurrentDb.OpenRecordset(strSQL, dbOpenDyanset)
Set myR2 as CurrentDb.OpenRecordset("Sold_Units_Table", dbOpenDynaset)

'This will edit the existing amount you have in the first table
myR.Edit
myR![Product_Qty] = myR![Product_Qty] - me.qty_sold
myR.Update

'This will add a new record of the transaction in the second table
myR2.addnew
myR2![Product_Sold] = me.product_field
myR2![Product_Qty_Sold] = me.qty_sold
myR2.Update

Set myR = Nothing
Set myR2 = Nothing

End Sub

VBA ルートに進みたい場合は、これが少し役立つことを願っています。

于 2013-06-21T01:32:45.600 に答える