การเพิ่มข้อมูลลงฐานข้อมูลเป็น Row ลงมา
Posted: Fri Jan 25, 2019 1:47 pm
Code: Select all
Private Sub CommandButton1_Click()
Dim irow, icol As Long
Dim ws As Worksheet
Set ws = Worksheets("DataInput")
'find first empty row in database
irow = ws.Cells(Rows.Count, 2)
.End(xlUp).Offset(1, 0).Row
'copy the data to the database
ws.Cells(irow, 2).Value = Me.Label23.Caption
ws.Cells(irow, 3).Value = Me.TextBox1.Value
ws.Cells(irow, 4).Value = Me.TextBox2.Value
ws.Cells(irow, 5).Value = Me.TextBox66.Value
ws.Cells(irow, 6).Value = Me.TextBox5.Value
ws.Cells(irow, 7).Value = Me.TextBox57.Value
ws.Cells(irow, 8).Value = Me.ComboBox1.Value
ws.Cells(irow, 9).Value = Me.TextBox6.Value
ws.Cells(irow, 10).Value = Me.TextBox7.Value
ws.Cells(irow, 11).Value = Me.TextBox10.Value
ws.Cells(irow, 12).Value = Me.TextBox12.Value
ws.Cells(irow, 2).Value = Me.TextBox17.Value
ws.Cells(irow, 3).Value = Me.TextBox20.Value
ws.Cells(irow, 4).Value = Me.TextBox21.Value
ws.Cells(irow, 16).Value = Me.TextBox22.Value
ws.Cells(irow, 17).Value = Me.TextBox25.Value
ws.Cells(irow, 18).Value = Me.TextBox26.Value
ws.Cells(irow, 19).Value = Me.TextBox27.Value
ws.Cells(irow, 20).Value = Me.TextBox30.Value
ws.Cells(irow, 21).Value = Me.TextBox31.Value
ws.Cells(irow, 22).Value = Me.TextBox37.Value
ws.Cells(irow, 23).Value = Me.TextBox40.Value
ws.Cells(irow, 24).Value = Me.TextBox41.Value
ws.Cells(irow, 25).Value = Me.TextBox42.Value
ws.Cells(irow, 26).Value = Me.TextBox45.Value
ws.Cells(irow, 27).Value = Me.TextBox46.Value
ws.Cells(irow, 28).Value = Me.TextBox47.Value
ws.Cells(irow, 29).Value = Me.TextBox50.Value
ws.Cells(irow, 30).Value = Me.TextBox51.Value
ws.Cells(irow, 31).Value = Me.TextBox52.Value
ws.Cells(irow, 32).Value = Me.TextBox55.Value
ws.Cells(irow, 33).Value = Me.TextBox56.Value
ws.Cells(irow, 34).Value = Me.TextBox67.Value
ws.Cells(irow, 35).Value = Me.TextBox70.Value
ws.Cells(irow, 36).Value = Me.TextBox71.Value
ws.Cells(irow, 37).Value = Me.TextBox72.Value
ws.Cells(irow, 38).Value = Me.TextBox75.Value
ws.Cells(irow, 39).Value = Me.TextBox76.Value
ws.Cells(irow, 40).Value = Me.TextBox77.Value
ws.Cells(irow, 41).Value = Me.TextBox80.Value
ws.Cells(irow, 42).Value = Me.TextBox81.Value
ws.Cells(irow + 1, 1).Value = Me.TextBox1.Value
ws.Cells(irow + 1, 2).Value = Me.TextBox2.Value
ws.Cells(irow + 1, 3).Value = Me.TextBox4.Value
ws.Cells(irow + 1, 4).Value = Me.ComboBox1.Value
ws.Cells(irow + 1, 5).Value = Me.TextBox5.Value
ws.Cells(irow + 1, 6).Value = Me.TextBox6.Value
ws.Cells(irow + 1, 7).Value = Me.TextBox7.Value
ws.Cells(irow + 1, 8).Value = Me.TextBox8.Value
ws.Cells(irow + 1, 9).Value = Me.TextBox9.Value
ws.Cells(irow + 1, 10).Value = Me.TextBox10.Value
'Clear the data
'Me.TextBox1.Value = ""
'Me.TextBox2.Value = ""
'Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox12.Value = ""
Me.TextBox21.Value = ""
Me.TextBox26.Value = ""
Me.TextBox31.Value = ""
Me.TextBox41.Value = ""
Me.TextBox46.Value = ""
Me.TextBox51.Value = ""
Me.TextBox56.Value = ""
Me.TextBox71.Value = ""
Me.TextBox76.Value = ""
Me.TextBox81.Value = ""
'Me.TextBox1.SetFocus
If CommandButton1 Then
UserForm1.Hide
End If
End Sub