Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Howmeny As Integer
Dim totalammount As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("Parts Inventory", dbOpenDynaset)
Me.Part_Type.SetFocus
If DCount("[Part Name]", "Parts Inventory", "[Part Name]= '" & Me.Part_Name & "'") > 0 Then
Else
With rs
.AddNew
.Fields("Part Name") = Me.Part_Name.Value
.Fields("Part Type") = Me.Part_Type.Value
.Fields("Total Ammount") = 0
.Update
End With
End If
rs.Close
Set rs = Nothing
Howmeny = Me.How_Meny.Value
totalammount = Nz(Me.Total_Ammount.Value, 0)
totalammount = totalammount + Howmeny
Me.Total_Ammount = totalammount
DoCmd.gotorecord
Me.Part_Type.SetFocus
End Sub
I have a dropdown and i want the program to add the record if it dose not exist in the table, therfore adding it to the dropdown and setting the stock level to 0. it adds it ok, puts the information in, adds in the ammount entered, but when i try to go to a new record i get this error:
The Microsoft access database engine cannot find a record in the table "Parts Inventory" with the key matching "Part Name"
I need them linked because when you select the name in the dropdown it brings up how meny of that item are in the inventory, i guess i could lookup ow meny are there with DLookup and editing the recordset via DAO, but is there anyway to get this to work?
Edit: if i close the form and re open it the part appears in the dropdown and the stock level is ok. and i do not receive the error for thate part. so it seems like i need to update, or refresh the dropdown or recordset somehow maybe??