Recordsets

Withnail

New member
Local time
Today, 17:07
Joined
Apr 5, 2001
Messages
7
Dear all,

I am trying to add a new record to a table by code (first time - quite excited).
Here is the code:

Dim Rst As Recordset

Set Rst = CurrentDb.OpenRecordset("Tbl_MTR_Development_Testing_Detail")

Rst.AddNew
Rst!MTR = Me.MTR.Value
Rst!Detail_Date = Date
Rst!Detail_Name = Me.MTR_Report_By.Value
Rst!Details = "New MTR"
Rst!Detail_Status = "MR"
Rst.Update

Set Rst = Nothing

I am receiving a type mismatch error which fails when setting the Recordset. Have I declared the recordset incorrectly? In the example code I used as a basis for this, the developer coded:

Dim rst as DAO.recordset.

I do not have the DAO option presented to me when declaring the variable.

Regards

Withnail
 
Are you using Access2000? If so then Access is expecting ADO code not DAO. Here it is in ADO which should work...

Dim Rst As New ADODB.Recordset

rs.Open "Tbl_MTR_Development_Testing_Detail",CurrentProject.Connection, adOpenDynamic, adLockOptimistic

Rst.AddNew
Rst!MTR = Me.MTR.Value
Rst!Detail_Date = Date
Rst!Detail_Name = Me.MTR_Report_By.Value
Rst!Details = "New MTR"
Rst!Detail_Status = "MR"
Rst.Update

Rst.Close
Set Rst = Nothing
 
Try adding a reference to the "Microsoft DAO 3.51 Object Library"...

1. Enter the VB editor.
2. To to the "Tools" menu
3. Select "References"
4. Scroll down the list until you see "Microsoft DAO 3.51 Object Library".
5. Check the checkbox.
6. Press ok.
7. now type the "Dim rst as DAO.recordset" line of code.

Hope this helps.
 

Users who are viewing this thread

Back
Top Bottom