Help with adding Record!

JBurlison

Registered User.
Local time
Today, 08:29
Joined
Mar 14, 2008
Messages
172
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??
 
Just requery the combo at the end of the code that adds it:

Me.YourComboName.Requery
 
the dropdown updates but im still getting the error
 
Is there a reason why you have this in there:

DoCmd.gotorecord
 
yah the function is a button that updates the ammount of a item that we have in stock. but if the item dose not exist it adds it, then updated the quanity in stock.

Its adds and updated the quantity alright, it even adds the new item to the table ok if it dose not exist. but i still get that error when trying to go to next record.

Is there a reason why you have this in there:

DoCmd.gotorecord

goes to next record, allowing the user to enter in another item.
 
The Microsoft Access database engine cannot find a record in the table <name> with key matching field(s) <name>. (Error 3101)



In a one-to-many relationship, you entered data on the "many" side for which there is no matching record on the "one" side. For example, this error occurs if you join a Customers table and Orders table on a CustomerID field, and then add an order using a CustomerID that does not exist in the Customers table.

Got this from the MS site.

how dose this apply to my problem?
 

Users who are viewing this thread

Back
Top Bottom