I want to use the following function"Spaces"in update query and to update the whole table records just in a single button click (to remove any unwanted spaces from the reocrds which wered already added earlier by mistake) instead of updating each record one by one. Because now, I have more than 6300 records in my MS Access database.

Note: I am not going to change any text / values in the textboxes. Simply I want to click onEditbutton then click onUpdatebutton to remove unwanted spaces from table records.

These (around 6300) records were added earlier without using Spaces function.

Code:Private Function Spaces(strText As String) As String Return String.Join(" ", strText.Split({" "}, StringSplitOptions.RemoveEmptyEntries)).Replace("( ", "(").Replace(" )", ")") End FunctionCode:Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click Dim CurrencyTextboxes() As TextBox = {txt17, txt18, txt19, txt20, txt22, txt23, txt24, txt25, txt26, txt27, txt28, txt29, txt30, txt31, txt32, txt33, txt34, txt36, txtTQty, txtTAmt, txtTDiscount, txtTTaxableValue, txtTCGST, txtSGST, txtInvoiceAmt, txtTTax, txtTInvoiceValue} For Each TB As TextBox In CurrencyTextboxes If TB.Text = "" Then TB.Text = 0.00 Next If btnSave.Text = "Save" Then Dim StrSql = "INSERT INTO NewSalesDBTable (A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20,A21,A22,A23,A24,A25,A26,A27,A28,A29,A30,A31,A32,A33,A34,A35,A36,A37,UDO,UDB) VALUES('" _ + Spaces(Me.txt1.Text) + "','" _ + Spaces(Me.txt2.Text) + "','" _ + Spaces(Me.txt3.Text) + "','" _ + Spaces(Me.txt4.Text) + "','" _ + Spaces(Me.txt5.Text) + "','" _ + Spaces(Me.txt6.Text) + "','" _ + Spaces(Me.txt7.Text) + "','" _ + Spaces(Me.txt8.Text) + "','" _ + Spaces(Me.txt9.Text) + "','" _ + Spaces(Me.txt10.Text) + "','" _ + Spaces(Me.txt11.Text) + "','" _ + Spaces(Me.txt12.Text) + "','" _ + Spaces(Me.txt13.Text) + "','" _ + Spaces(Me.txt14.Text) + "','" _ + Spaces(Me.txt15.Text) + "','" _ + Spaces(Me.txt16.Text) + "','" _ + Spaces(Me.txt17.Text) + "','" _ + Spaces(Me.txt18.Text) + "','" _ + Spaces(Me.txt19.Text) + "','" _ + Spaces(Me.txt20.Text) + "','" _ + Spaces(Me.txt21.Text) + "','" _ + Spaces(Me.txt22.Text) + "','" _ + Spaces(Me.txt23.Text) + "','" _ + Spaces(Me.txt24.Text) + "','" _ + Spaces(Me.txt25.Text) + "','" _ + Spaces(Me.txt26.Text) + "','" _ + Spaces(Me.txt27.Text) + "','" _ + Spaces(Me.txt28.Text) + "','" _ + Spaces(Me.txt29.Text) + "','" _ + Spaces(Me.txt30.Text) + "','" _ + Spaces(Me.txt31.Text) + "','" _ + Spaces(Me.txt32.Text) + "','" _ + Spaces(Me.txt33.Text) + "','" _ + Spaces(Me.txt34.Text) + "','" _ + Spaces(Me.txt35.Text) + "','" _ + Spaces(Me.txt36.Text) + "','" _ + Spaces(Me.txt37.Text) + "','" _ + Spaces(Me.txtUDO.Text) + "','" _ + Spaces(Me.txtUDB.Text) + "')" Dim dt As New DataTable If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Exit Sub Else Dim StrSql = "UPDATE NewSalesDBTable SET " _ + "A1='" + Spaces(Me.txt1.Text) + "'," _ + "A2='" + Spaces(Me.txt2.Text) + "'," _ + "A3='" + Spaces(Me.txt3.Text) + "'," _ + "A4='" + Spaces(Me.txt4.Text) + "'," _ + "A5='" + Spaces(Me.txt5.Text) + "'," _ + "A6='" + Spaces(Me.txt6.Text) + "'," _ + "A7='" + Spaces(Me.txt7.Text) + "'," _ + "A8='" + Spaces(Me.txt8.Text) + "'," _ + "A9='" + Spaces(Me.txt9.Text) + "'," _ + "A10='" + Spaces(Me.txt10.Text) + "'," _ + "A11='" + Spaces(Me.txt11.Text) + "'," _ + "A12='" + Spaces(Me.txt12.Text) + "'," _ + "A13='" + Spaces(Me.txt13.Text) + "'," _ + "A14='" + Spaces(Me.txt14.Text) + "'," _ + "A15='" + Spaces(Me.txt15.Text) + "'," _ + "A16='" + Spaces(Me.txt16.Text) + "'," _ + "A17='" + Spaces(Me.txt17.Text) + "'," _ + "A18='" + Spaces(Me.txt18.Text) + "'," _ + "A19='" + Spaces(Me.txt19.Text) + "'," _ + "A20='" + Spaces(Me.txt20.Text) + "'," _ + "A21='" + Spaces(Me.txt21.Text) + "'," _ + "A22='" + Spaces(Me.txt22.Text) + "'," _ + "A23='" + Spaces(Me.txt23.Text) + "'," _ + "A24='" + Spaces(Me.txt24.Text) + "'," _ + "A25='" + Spaces(Me.txt25.Text) + "'," _ + "A26='" + Spaces(Me.txt26.Text) + "'," _ + "A27='" + Spaces(Me.txt27.Text) + "'," _ + "A28='" + Spaces(Me.txt28.Text) + "'," _ + "A29='" + Spaces(Me.txt29.Text) + "'," _ + "A30='" + Spaces(Me.txt30.Text) + "'," _ + "A31='" + Spaces(Me.txt31.Text) + "'," _ + "A32='" + Spaces(Me.txt32.Text) + "'," _ + "A33='" + Spaces(Me.txt33.Text) + "'," _ + "A34='" + Spaces(Me.txt34.Text) + "'," _ + "A35='" + Spaces(Me.txt35.Text) + "'," _ + "A36='" + Spaces(Me.txt36.Text) + "'," _ + "A37='" + Spaces(Me.txt37.Text) + "'," _ + "UDO='" + Spaces(Me.txtUDO.Text) + "'," _ + "UDB='" + Spaces(Me.txtUDB.Text) + "' Where [TINVID] = " & txtID.Text Dim dt As New DataTable If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Exit Sub End If End Sub