ongke0711 > 19-07-17, 04:54 PM
Option Compare Database
Option Explicit
Public Function SetFocusHandlers(ByRef frm As Form)
Dim ctl As Control
On Error GoTo 0
For Each ctl In frm
If ctl.Tag = "HighlightOnFocus" Then
ctl.OnGotFocus = "=HandleFocus([" & ctl.Name & "], True)"
ctl.OnLostFocus = "=HandleFocus([" & ctl.Name & "], False)"
End If
Next
End Function
Public Function HandleFocus(ByRef ctl As Control, ByVal blnFocus As Boolean)
If blnFocus = True Then
'ctl.BackColor = RGB(200, 237, 248) 'RGB(222, 239, 229)
ctl.BorderColor = RGB(&HF9, &HCB, &H8E)
ctl.BorderWidth = 2
Else
'ctl.BackColor = RGB(255, 255, 255)
ctl.BorderColor = RGB(&H98, &HBD, &HE0)
ctl.BorderWidth = 1
End If
End Function
Option Compare Database
Option Explicit
Public str As String
Public colCtlName As New Collection
Function IsNullOrEmpty(tbx As Control) As Boolean
If IsNull(tbx.Value) Or _
Len(Nz(tbx, vbNullString)) = 0 Or _
Len(Nz(tbx & vbNullString)) = 0 Then
IsNullOrEmpty = True
Else
IsNullOrEmpty = False
End If
End Function
Function CheckNullEmpty(frm As Form) As Boolean
Dim ctl As Control
str = Empty
For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acCheckBox Then
If Right(ctl.Tag, 8) = "required" Then
If IsNullOrEmpty(ctl) Then
'Debug.Print IsNullOrEmpty(ctl) & " - " & ctl.Name'
colCtlName.Add ctl.Name 'De setFocus vao control dau tien trong danh sách collection'
ctl.BackColor = RGB(255, 255, 153)
str = str & "- " & ctl.Controls(0) & vbNewLine
End If
End If
End If
Next
If Len(str) = 0 Then
CheckNullEmpty = False
Else
CheckNullEmpty = True
End If
End Function
Function ClearControlFormatting(ctl As Control)
ctl.BackColor = vbWhite
End Function
ongke0711 > 19-07-17, 09:24 PM
Controls(colCtlName(1)).SetFocus
Set colCtlName = Nothing
Exit Sub
thanhtruong > 21-07-17, 08:44 PM