LO Base - How to create a recordset to add new records - Access2Base

I’m getting a - Error 91: Object variable not set - error when I try to assign a value to the first field after I issue the AddNew method. The iYear does have a good value.

strDQ = chr(34)
strRptNumSel = "SELECT * FROM " & strDQ & "ReportNum" & strDQ 
set myRecSetRptNum = Application.CurrentDb().OpenRecordset(strRptNumSel,,,)
With myRecSetRptNum
.AddNew
.Fields("Year") = iYear 'integer - error occurs on this line
.Fields("Rnum") = iRptNum 'integer
.Fields("REID") = iRptEID.value 'variant
.Update
End With

Andrew, Pitonyak, Database access using OpenOffice.org

The example on the Access2Base website for .AddNew shows a slightly different syntax:

Dim oRecordset As Object
Set oRecordset = Application.CurrentDb().OpenRecordset("Expenses")
With oRecordset	
	.AddNew				'	Fields initialised with the default value
	.Fields("AMOUNT").Value = 1234
	.Fields("DATE EXPENSE").Value = Now()
	.Fields("CATEGORY").Value = "Food"
	.Fields("DESCRIPTION").Value = "Lunch"
	.Fields("VAT CODE").Value = 3
	.Update
	.mClose
End With
2 Likes

The original post code works (tested with different table) if the fields add .Value such as:

.Fields("Year").Value = iYear
1 Like