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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DAO 3.6: Error 2427 when reading new record 1

Status
Not open for further replies.

goaway1234

Programmer
Jun 2, 2004
78
US
In an application that I just migrated from Access 97 to 2003, I have a form that creates a new record when it is opened, and then sets the RecordSource of the form to just that record. Here is the code that is generating the error.
Code:
Set rst = CurrentDb.OpenRecordset("tblActions", dbOpenDynaset)
rst.AddNew
rst![RootID] = lngRootID
lngActionID = rst![ActionID]
rst.Update
rst.Close

In this code, lngActionID is a private class variable that is used later, and ActionID is an Auto Number field that is the primary key of tblActions. Whenever the assignment 'lngActionID = rst![ActionID]' is made, the user will sometimes get error 2427 "You entered an expression with no value."

The error doesn't happen every time the code is run, and it didn't ever happen in Access 97. Anybody have an idea of what is going on here?
 
To make sure the record is created (saved) prior to fetching the newly generated autonumber, try:

[tt]rst.AddNew
rst![RootID] = lngRootID
rst.Update
rst.bookmark=rst.lastmodified
lngActionID = rst![ActionID]
rst.Close[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top