[RESOLVED] datagrid and delete or edit button
edit
Code:
Dim editRecord As String
Dim fnd As String
Dim varbookmark
varbookmark = adodcReports.Recordset.Bookmark
editRecord = InputBox("Please input record ID", "Edit")
fnd = "end_of_day_report_id=" & "'" & editRecord & "'"
If editRecord = "" Then
Exit Sub
ElseIf IsNumeric(editRecord) = False Then
MsgBox "Please input numbers only.", vbOKOnly, ""
Else
With adodcReports
.Recordset.MoveFirst
.Recordset.Find fnd, 0
If .Recordset.EOF = True Then
MsgBox "Record not found.", vbOKOnly, ""
.Recordset.Bookmark = varbookmark
Else
txtBranchID.Text = .Recordset.Fields("branch_id")
txtTotalSales.Text = .Recordset.Fields("total_sales")
txtTotalExpenses.Text = .Recordset.Fields("total_expenses")
txtDetailsExpenses.Text = .Recordset.Fields("details_expenses")
txtTotalUnsold.Text = .Recordset.Fields("total_unsold")
txtRemarks.Text = .Recordset.Fields("remarks")
cmdEdit.Enabled = False
cmdDelete.Enabled = False
cmdAdd.Visible = False
cmdSave.Visible = True
End If
End With
End If
delete
Code:
Dim fnd As String
Dim deleteID As String
Dim x As String
Dim varbookmark
deleteID = InputBox("Input ID", "Delete")
fnd = "end_of_day_report_id=" & "'" & deleteID & "'"
If deleteID = "" Then
Exit Sub
ElseIf IsNumeric(deleteID) = False Then
MsgBox "Please input numbers only.", vbOKOnly, ""
Else
With adodcReports
.Recordset.MoveFirst
.Recordset.Find fnd, 0
If .Recordset.EOF = True Then
MsgBox "Report not found.", vbOKOnly, ""
Else
txtBranchID.Text = .Recordset.Fields("branch_id")
txtTotalSales.Text = .Recordset.Fields("total_sales")
txtTotalExpenses.Text = .Recordset.Fields("total_expenses")
txtDetailsExpenses.Text = .Recordset.Fields("details_expenses")
txtTotalUnsold.Text = .Recordset.Fields("total_unsold")
txtRemarks.Text = .Recordset.Fields("remarks")
x = MsgBox("Are you sure you wish to delete?", vbYesNo, "")
If x = vbYes Then
.Recordset.Delete
.Refresh
Adodc1.Refresh
Call clearControl(Me)
MsgBox "Report Deleted.", vbOKOnly, ""
Else
Call clearControl(Me)
.Recordset.Cancel
End If
End If
End With
End If
i have a datagrid named dGridEndOfDayReport what i want to know is how can i get the ID just by clicking on the datagrid row. so when i click edit or delete. i will just have confirmation to edit or to delete..
hope you can help
Re: datagrid and delete or edit button
Thread moved to 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums)
Re: datagrid and delete or edit button
Just access the ADODC's underlying recordset. It really is no different than setting the TextBox values.
Code:
Private Sub cmdDelete_Click()
If MsgBox("Delete Record Id " & Adodc1.Recordset.Fields("end_of_day_report_id").Value, vbYesNo) = vbYes Then
Adodc1.Recordset.Delete
End If
End Sub
Re: datagrid and delete or edit button