Chào các bác
Sau một thời gian mày mò coding với sự hỗ trợ tuyệt vời đến từ các thành viên GPE, em đã gần hoàn thiện sản phẩm đầu tiên.
Em có một thắc mắc trên bối cảnh sau:
- Gõ mã số khách hàng vào textbox trên userform, bấm nút search để hiện thị các thông tin đã nhập vào thông qua chính userform này.
- Các dữ liệu nhập vào bằng textbox thì hiển thị bình thường
- Các dữ liệu nhập vào bằng Option Button hoặc Checkbox thì không hiển thị.
VD: Nút Individual, lúc đầu em lựa chọn và bấm lưu, trên sheet tại cột Individual sẽ hiển thị chữ Yes tương ứng.
Giờ em muốn với giá trị Yes, Checkbox sẽ được chọn khi search dữ liệu.
Với các checkbox không có chữ Yes (trống) thì sẽ trả lại giá trị trống (checkbox trên userform không check)
Em cảm ơn.
Code em sử dụng:
'Tim kiem khach hang, liet ke vao form
Private Sub cmbFind_Click()
Dim Nullstring
Application.ScreenUpdating = False
If iqc_code.Value = "" Or Nullstring Then
MsgBox "Dien ma so khach hang IQC de tim kiem"
'GoTo error1:
End If
Sheet5.Activate
Dim strFind
Dim rSearch As Range 'range to search
Set rSearch = Sheet5.Range("C1", Range("C1000").End(xlUp))
Dim c
strFind = iqc_code.Value
If strFind = Nullstring Then GoTo error1
With rSearch
Set c = .Find(strFind, LookIn:=xlValues, MatchCase:=True)
If Not c Is Nothing Then 'found it
Select Case MsgBox("Ma so khach hang " & strFind & " co trong du lieu", vbOKCancel Or vbExclamation Or vbDefaultButton1)
Case vbOK
Case vbCancel
'do nothing
End Select
c.Select
Me.Height = 430.2
Me.Width = 693
With Me 'load du lieu vao form
.cmb_edit_save.Enabled = True 'cho phep chinh sua va luu lai du lieu
.cmb_delete.Enabled = True 'cho phep xoa du lieu
.cmbt_save.Enabled = False 'khong cho Add du lieu
.client_name.Value = c.Offset(0, -1).Value 'phan nay hien thi tot
.iqc_code.Value = c.Offset(0, 0).Value 'phan nay hien thi tot
.postal_code.Value = c.Offset(0, 1).Value 'phan nay hien thi tot
.address.Value = c.Offset(0, 2).Value 'phan nay hien thi tot
.province.Value = c.Offset(0, 3).Value 'phan nay hien thi tot
.phone_congty.Value = c.Offset(0, 4).Value 'phan nay hien thi tot
.responsible_person.Value = c.Offset(0, 5).Value 'phan nay hien thi tot
.chuc_vu.Value = c.Offset(0, 6).Value 'phan nay hien thi tot
.email.Value = c.Offset(0, 7).Value 'phan nay hien thi tot
.ggn_number.Value = c.Offset(0, 8).Value 'phan nay hien thi tot
.contact_person.Value = c.Offset(0, 9).Value 'phan nay hien thi tot
.phone_lienhe.Value = c.Offset(0, 10).Value 'phan nay hien thi tot
If cb_individual_producer.Value = "Yes" Then c.Offset(0, 11).Value ' phan nay chua hien thi
If cb_individual_producer.Value = "" Then c.Offset(0, 11).Value ' phan nay chua hien thi
Sau một thời gian mày mò coding với sự hỗ trợ tuyệt vời đến từ các thành viên GPE, em đã gần hoàn thiện sản phẩm đầu tiên.
Em có một thắc mắc trên bối cảnh sau:
- Gõ mã số khách hàng vào textbox trên userform, bấm nút search để hiện thị các thông tin đã nhập vào thông qua chính userform này.
- Các dữ liệu nhập vào bằng textbox thì hiển thị bình thường
- Các dữ liệu nhập vào bằng Option Button hoặc Checkbox thì không hiển thị.
VD: Nút Individual, lúc đầu em lựa chọn và bấm lưu, trên sheet tại cột Individual sẽ hiển thị chữ Yes tương ứng.
Giờ em muốn với giá trị Yes, Checkbox sẽ được chọn khi search dữ liệu.
Với các checkbox không có chữ Yes (trống) thì sẽ trả lại giá trị trống (checkbox trên userform không check)
Em cảm ơn.
Bài đã được tự động gộp:
Code em sử dụng:
'Tim kiem khach hang, liet ke vao form
Private Sub cmbFind_Click()
Dim Nullstring
Application.ScreenUpdating = False
If iqc_code.Value = "" Or Nullstring Then
MsgBox "Dien ma so khach hang IQC de tim kiem"
'GoTo error1:
End If
Sheet5.Activate
Dim strFind
Dim rSearch As Range 'range to search
Set rSearch = Sheet5.Range("C1", Range("C1000").End(xlUp))
Dim c
strFind = iqc_code.Value
If strFind = Nullstring Then GoTo error1
With rSearch
Set c = .Find(strFind, LookIn:=xlValues, MatchCase:=True)
If Not c Is Nothing Then 'found it
Select Case MsgBox("Ma so khach hang " & strFind & " co trong du lieu", vbOKCancel Or vbExclamation Or vbDefaultButton1)
Case vbOK
Case vbCancel
'do nothing
End Select
c.Select
Me.Height = 430.2
Me.Width = 693
With Me 'load du lieu vao form
.cmb_edit_save.Enabled = True 'cho phep chinh sua va luu lai du lieu
.cmb_delete.Enabled = True 'cho phep xoa du lieu
.cmbt_save.Enabled = False 'khong cho Add du lieu
.client_name.Value = c.Offset(0, -1).Value 'phan nay hien thi tot
.iqc_code.Value = c.Offset(0, 0).Value 'phan nay hien thi tot
.postal_code.Value = c.Offset(0, 1).Value 'phan nay hien thi tot
.address.Value = c.Offset(0, 2).Value 'phan nay hien thi tot
.province.Value = c.Offset(0, 3).Value 'phan nay hien thi tot
.phone_congty.Value = c.Offset(0, 4).Value 'phan nay hien thi tot
.responsible_person.Value = c.Offset(0, 5).Value 'phan nay hien thi tot
.chuc_vu.Value = c.Offset(0, 6).Value 'phan nay hien thi tot
.email.Value = c.Offset(0, 7).Value 'phan nay hien thi tot
.ggn_number.Value = c.Offset(0, 8).Value 'phan nay hien thi tot
.contact_person.Value = c.Offset(0, 9).Value 'phan nay hien thi tot
.phone_lienhe.Value = c.Offset(0, 10).Value 'phan nay hien thi tot
If cb_individual_producer.Value = "Yes" Then c.Offset(0, 11).Value ' phan nay chua hien thi
If cb_individual_producer.Value = "" Then c.Offset(0, 11).Value ' phan nay chua hien thi