Hi,
I have a program that generates Crystal reports. I want to keep track of the reports and when they were generated so I have a reports table and a reports history table (in SQL). My code adds a new record to the history table for every report, but what I also need is for a field in the reports table to be edited to contain the current report filename. My code for adding a record is as follows:
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim objErr As ADODB.Error
objConn.Open "Driver=SQL Server;Server=xxx;Database=xxx;uid=xxx;password=xxx"
objConn.BeginTrans
objRS.Open "Select * from ReportsHistory", objConn, adOpenStatic, adLockPessimistic
objRS.AddNew
objRS.Fields("ReportID" = txtTPID.Text
objRS.Fields("Gen_Date" = Date
objRS.Fields("Report_Name" = txtTPID.Text & txtMonth.Text
objRS.Update
If MsgBox("Are you sure?", vbYesNo + vbQuestion) = vbYes Then
objConn.CommitTrans
Else
objConn.RollbackTrans
End If
This works fine, but how do I edit a record in a database, not just add a new record?
Thanks very much, Kate
I have a program that generates Crystal reports. I want to keep track of the reports and when they were generated so I have a reports table and a reports history table (in SQL). My code adds a new record to the history table for every report, but what I also need is for a field in the reports table to be edited to contain the current report filename. My code for adding a record is as follows:
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim objErr As ADODB.Error
objConn.Open "Driver=SQL Server;Server=xxx;Database=xxx;uid=xxx;password=xxx"
objConn.BeginTrans
objRS.Open "Select * from ReportsHistory", objConn, adOpenStatic, adLockPessimistic
objRS.AddNew
objRS.Fields("ReportID" = txtTPID.Text
objRS.Fields("Gen_Date" = Date
objRS.Fields("Report_Name" = txtTPID.Text & txtMonth.Text
objRS.Update
If MsgBox("Are you sure?", vbYesNo + vbQuestion) = vbYes Then
objConn.CommitTrans
Else
objConn.RollbackTrans
End If
This works fine, but how do I edit a record in a database, not just add a new record?
Thanks very much, Kate