I'm creating a library which when everytime i add new book, i always get the 'Update or CancelUpdate without addnew or edit'.The condition is when the user inputs a new ISBN that is already in the database, the message box will prompt as "That book is already listed!', else if the inputted ISBN is not yet listed in the database, that new book isbn and all its information will be saved, but everytime i hit the save button, that error will generate. Help please.... I am using the Data Control and the MS access as instructed by our prof.
Thanks...

here are the codes i have.

Private Sub cmdSave_Click()
Dim isbn As String
Dim msg As String

dtaAdd.Refresh
isbn = txtisbnadd

Do Until dtaAdd.Recordset.EOF
If dtaAdd.Recordset.Fields("ISBN").Value = isbn Then

MsgBox "That book ISBN is already rented. ", vbOKCancel + vbInformation, "Book already on the database"



Exit Sub

Else
dtaAdd.Recordset.MoveNext
End If

Loop
dtaAdd.Refresh
dtaAdd.Recordset.Update

msg = MsgBox("Data has been saved. ", vbOKOnly + vbInformation, "Saving Successful!")
End Sub

your reply is highly acknowledge... thanks...

Recommended Answers

All 5 Replies

You are calling an update function on your data control without a command to add the data first, hence your error. -

dtaAdd.Refresh
dtaAdd.Recordset.Update

Add some data to add to the database first, then call the update function.

You are calling an update function on your data control without a command to add the data first, hence your error. -

dtaAdd.Refresh
dtaAdd.Recordset.Update

Add some data to add to the database first, then call the update function.

so what code i am going to add to fix it?

If you are using a data control, set your textboxes datasource to dtaAdd, their respective datafield to the field it reference and add -

dtaAdd.Recordset.Add

After this the dtaAdd.Update

Thanks! You solved my problem...

It's a pleasure. Please mark this post as solved, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.