I am trying to convert an mdb to VB6. I want to create a new record, assign a value to a field that is one greater than the highest existing value for that field, and open a form to the new record. Using the following code, I get the above error, and I don't know why!
Code:
Private Sub btnNew_Click(Index As Integer)
Dim ws As Workspace
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim dblAccountNum As Double
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase("ArtWare.mdb")
strSQL = "SELECT * FROM tblClients " & _
" ORDER BY nfldAccountNum ASC;"
Set rs = db.OpenRecordset(strSQL)
With rs
.MoveLast
!nfldAccountNum = dblAccountNum
.AddNew
!nfldAccountNum = dblAccountNum + 1
.Update
.MoveLast
End With
Load frmClient
frmClient.Show
With frmClient
.txtidxClients = rs!idxClients
End With
rs.Close
db.Close
ws.Close
Set rs = Nothing
Set db = Nothing
Set ws = Nothing
End Sub