G
Guest
I know this is really basic, but I can't remember how to add a record to a
table and I can't find a full example to copy.
I am keeping a log in tblReportLog of a certain report. Each time I run the
report, I want to assign it the next higher index number and store that
number (along with other fields) in a new record. I seem to have figured out
how read the ReportIndex number from the highest record already in
tblReportLog. I then have added one (1) to the ReportIndex. However, I am
frustrated that I can’t remember how to write the new record to the table.
What you see are my attempts, but they don’t work. Would someone mind solving
this for me.
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim lng As Long
Dim dbs As Database
Dim rst As Recordset
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("SELECT ReportIndex FROM tblReportLog")
rst.MoveLast
lng = rst!ReportIndex + 1
rst!ReportIndex = lng
rst!ReportDate = #1/11/2005#
rst!ReportType = "I"
With rst
.AddNew
.Update
.Close
End With
Exit_Command0_Click:
Set dbs = Nothing
Set rst = Nothing
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
table and I can't find a full example to copy.
I am keeping a log in tblReportLog of a certain report. Each time I run the
report, I want to assign it the next higher index number and store that
number (along with other fields) in a new record. I seem to have figured out
how read the ReportIndex number from the highest record already in
tblReportLog. I then have added one (1) to the ReportIndex. However, I am
frustrated that I can’t remember how to write the new record to the table.
What you see are my attempts, but they don’t work. Would someone mind solving
this for me.
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim lng As Long
Dim dbs As Database
Dim rst As Recordset
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("SELECT ReportIndex FROM tblReportLog")
rst.MoveLast
lng = rst!ReportIndex + 1
rst!ReportIndex = lng
rst!ReportDate = #1/11/2005#
rst!ReportType = "I"
With rst
.AddNew
.Update
.Close
End With
Exit_Command0_Click:
Set dbs = Nothing
Set rst = Nothing
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub