PRB: No Current Record Error In VB When Database is EmptyLast reviewed: June 21, 1995Article ID: Q106494 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SYMPTOMSIf a data control and text box are both bound to an empty table in a database, clicking the data control arrows gives this error:
No Current RecordThis error also occurs if you enter text into the text box, and execute the AddNew method or the Edit method while the database table is empty. The program has difficulty recovering because of the recurring "No Current Record" errors. The On Error statement fails to trap this error.
CAUSEThe program does not know the table is empty until the automatic record update occurs. That automatic record update occurs when you click the data control arrow or you enter text in the text box and then execute an AddNew or Edit method. When the table is not empty the automatic update is a nice feature, but when the table is empty the automatic update causes the no current record error. The error message occurs because the underlying recordset contains no records. You must execute AddNew to create a current record before doing anything that causes an automatic record update.
WORKAROUNDTo work around this behavior, execute the AddNew method on an empty database table before allowing the user to click the data control or enter text into the bound text box control. For example, set the Enabled property for the text control and data control to False at the beginning of the program. Then you can force the user to click a command button that executes the AddNew method before enabling the text and data controls.
STATUSThis behavior is by design. This design is under review and will be considered for enhancement in a future release.
More Information
How to Create an Empty Microsoft Access DatabaseBefore using Example 1 or 2 shown below, create an empty database by following these steps in Visual Basic:
Example One: Steps to Reproduce Behavior using a Data Control
Example One WorkaroundTo work around this behavior, set the Enabled property for the text and data controls to False at design time or in the Load procedure for the form. Then add the following to the top of the Command1_Click procedure before the AddNew:
Data1.enabled = True Text1.enabled = TrueThis prevents the user from automatically updating an empty database, thus avoiding the no current record error.
Example Two: Steps to Reproduce Behavior Using Object Variables
REFERENCESAdditional information can be found in the Visual Basic Help menu. The no current record error is described in the Visual Basic Help topic "Data Access error messages." Here is that description:
No current record. Error 3021. This error occurs following the unsuccessful application of one of the FindFirst, FindLast, FindNext, FindPrevious Methods or the Seek Method, or when the underlying recordset contains no records. Move to or select a record, and then try the operation again.The following is paraphrased from the Help topic for AddNew in Visual Basic:
The AddNew method clears the copy buffer in preparation for creating a new record in a Table or Dynaset. AddNew sets all fields in the copy buffer to Null and makes it the current record. After putting data in the record, you can use the Update method to add the record to the recordset. Update is automatically invoked with a data control if an Edit or AddNew operation is pending when you use one of the Find or Move methods. |
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |