Sorry about that, you already have a field Product in the Repairs table. Ignore that dumb statement of mine.
You really should have your ComboBox bound to the Repairs table field Product. Otherwise you will be entering it twice. Also, this will make the SAVE of the record to Repairs very easy as all of the information is on the form. Also, the primary key should be more than just the Product field. Otherwise you can only have one record with a product number. Probably a combination of all three fields: Product, Date, and Number Used.
If you want the User to select by the
Description. Use the following SQL as the RowSource.
Code:
Select A.Description & "(" & A.Products & ")" as Product_Description, A.Products FROM Products as A ORDER BY A.Description;
If you want the User to select by the
Products. Use the following SQL as the RowSource.
Code:
Select A.Products & " - " & A.Description as Product_Description, A.Products FROM Products as A ORDER BY A.Products;
Change the Bound Column to
2, Column Widths:
3";0
Create a Command Button on your form with a caption of
SAVE. Put the following VBA code in the OnClick Event Procedure of this command button.
Code:
Dim db as DAO.Database
Dim rs as DAO.Recordset
Set db = CurrentDB
If IsNull Me![cboProducts] then
db.close
MsgBox "Product selection must be made before SAVE"
Me![cboProducts].SetFocus
Exit Sub
End If
Set rs = db.OpenRecordset("Products", dbOpenDynaset)
rs.FindFirst "[Products] = '" & Me![cboProducts].column(1) & "'"
If Not rs.NoMatch then
rs.Edit
rs("InStock") = rs("InStock") - Me![NumberUsed]
rs.Update
DoCmd.RunCommand acCmdSaveRecord
else
MsgBox "No Product Record found"
End If
rs.close
db.close
After trying this post back with the results.
Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]