iam using datagrid for data entry ,i have added ,add button remove button...but now i want an update button which can update the entries to database from data grid...
here is code

Option Explicit

' couple'o global vars for size trackin'
Dim MinHeight As Long
Dim MinWidth As Long

Private Sub cmdAddEntry_Click()
' add a new entry to our table.
    With DataEnvironment.rsDataTable
        .AddNew
        !Date = txtDate
        !CodeNo = txtCodeNo
        !DealerName = txtDealerName
        !TruckNumber = txtTruckNumber
        !Product = txtProduct
        !Quantity = txtQuantity
        !NetPrice = txtNetPrice
        !Commision = txtCommision
        !Rent = txtRent
        !Labour = txtLabour
        !ReturnExpense = txtReturnExpense
        !Expense2 = txtExpense2
        !StoreExpense = txtStoreExpense
        !PhoneExpense = txtPhoneExpense
        !Expense3 = txtExpense3
        !TotalExpense = txtTotalExpense
        !Total = txtTotal
        
        .Update
    End With
    
    ' requery the db and re-bind the data source to the data grid
    DataEnvironment.rsDataTable.Requery
    Set DataGrid1.DataSource = DataEnvironment
    
    ' clear the text fields once the new record is added
    txtDate.Text = ""
    txtCodeNo.Text = ""
    txtDealerName.Text = ""
    txtTruckNumber.Text = ""
    txtProduct.Text = ""
    txtQuantity.Text = ""
    txtNetPrice.Text = ""
    txtCommision.Text = ""
    txtRent.Text = ""
    txtLabour.Text = ""
    txtReturnExpense.Text = ""
    txtExpense2.Text = ""
    txtStoreExpense.Text = ""
    txtPhoneExpense.Text = ""
    txtExpense3.Text = ""
    txtTotalExpense.Text = ""
    txtTotal.Text = ""
   
    ' set the focus back to the CodeNo textbox
    txtDate.SetFocus

End Sub

Private Sub cmdExit_Click()
End
End Sub

Private Sub cmdPrint_Click()
cmdPrint.Visible = False

cmdExit.Visible = False

PrintForm

cmdPrint.Visible = True

cmdExit.Visible = True
End Sub

Private Sub cmdRemoveEntry_Click()
    ' remove the currently selected item from the database
    DataEnvironment.rsDataTable.Delete adAffectCurrent

End Sub

Private Sub Command2_Click()

End Sub

Private Sub cmdUpdate_Click()
-------------------------------------------------------update code need here...

Private Sub DataGrid1_Click()
    cmdRemoveEntry.Enabled = True
End Sub

Recommended Answers

All 3 Replies

Use the exact same code you have under cmdAddEntry button WITHOUT the .AddNew -

With DataEnvironment.rsDataTable
        'Remove AddNew here...
        !Date = txtDate
        !CodeNo = txtCodeNo
        !DealerName = txtDealerName
        !TruckNumber = txtTruckNumber
        !Product = txtProduct
        !Quantity = txtQuantity
        !NetPrice = txtNetPrice
        !Commision = txtCommision
        !Rent = txtRent
        !Labour = txtLabour
        !ReturnExpense = txtReturnExpense
        !Expense2 = txtExpense2
        !StoreExpense = txtStoreExpense
        !PhoneExpense = txtPhoneExpense
        !Expense3 = txtExpense3
        !TotalExpense = txtTotalExpense
        !Total = txtTotal
 
        .Update
    End With

Thnx AdreRet

It was a pleasure. Happy coding.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.