Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recordset.addnew method

Status
Not open for further replies.

Waynest

Programmer
Jun 22, 2000
321
GB
Hi, I have a a frustrating problem.

I have some code which uses the addnew method to create some new records - its an access 2000 event procedure updating a sql server 7 database. It works fine when there are 1 or more records in the table, but I get the following message when the table is empty

Either BOF or EOF is true... blah...the application requires a current record

I open the recordset as follows..

rstTicket.CursorType = adOpenKeyset
rstTicket.LockType = adLockOptimistic
rstTicket.Open "Ticket", cnn1, , , adCmdTable

Attempting to movefirst or movelast before an addnew results in the same message. So how do you use .addnew when the table is empty?
 
On an empty recordset you can't do any moves, and you can't display any records. You could try putting in an empty record if table is empty(if you can, i don't know how your table is set up) or check for .bof and .eof before any moves or displaying records and do an alternate routine.
David Paulson


 
The addnew must be the first statement. You cannot reference any field in a table that is empty.

You need to have an "if" statement immediately following your "open" that checks for an empty result.

ie:

table.open etc

if table.bof then
addnew
populate fields, etc
table.update
else
display/reference fields
other code modify fields
table.update
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top