Results 1 to 4 of 4

Thread: [RESOLVED] datagrid and delete or edit button

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Resolved [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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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)

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Re: datagrid and delete or edit button

    tnx for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width