1. แก้ไข Code ในหน้า Add ตรง Me.TextBox1.Value เป็น Me.TextBox1
Code: Select all
Private Sub CommandButton1_Click()
If Me.TextBox1.Value <> "" Then
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("DATA")
Me.TextBox1.Text = Application.Trim(Me.TextBox1.Text)
'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.TextBox1
ws.Cells(irow, 5).Value = Me.TextBox2.Value
ws.Cells(irow, 3).Value = Me.TextBox3.Value
ws.Cells(irow, 4).Value = Me.TextBox4.Value
ws.Cells(irow, 6).Value = Me.TextBox5.Value
ws.Cells(irow, 7).Value = Me.TextBox6.Value
ws.Cells(irow, 8).Value = Me.TextBox7.Value
Unload Me
Add_frrm.Show
Else
MsgBox "¡ÃسÒÃкت×è͹Ó˹éÒ¡è͹¤ÃѺ", vbCritical
End If
End Sub
2. แก้ไข Code ในหน้าแก้ไข i = Application.Match(VBA.CLng(Me.ComboBox1.Value), sh.Range("B:B"), 0) เป็น i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Code: Select all
Private Sub ComboBox1_Change()
If Me.ComboBox1.Value <> "" Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Me.TextBox2.Value = sh.Range("E" & i).Value
Me.TextBox3.Value = sh.Range("C" & i).Value
Me.TextBox4.Value = sh.Range("D" & i).Value
Me.TextBox5.Value = sh.Range("F" & i).Value
Me.TextBox6.Value = sh.Range("G" & i).Value
Me.TextBox7.Value = sh.Range("H" & i).Value
End If
End Sub
เพื่อให้ Format เป็นรูปแบบเดียวกันครับ