' To allow user to check if the text field is blank show red if it is blank and prompt to Enter
Public Function isblank(ByVal txtbox As TextBox) As Boolean
On Err GoTo Err:
If txtbox.Text = "" Or IsNull(txtbox) Then
txtbox.SetFocus
txtbox.BackColor = &HC0C0FF 'red
isblank = True
Else
txtbox.BackColor = vbWhite
End If
Exit Function
Err:
MsgBox Err.Description
isblank = False
End Function
' To allow user to insert only character in the text field
Public Function ValidateString(strInputString As String)
'Can enter a to z A to Z 0 to 9 and _ only
'97 a 122 z 65A 90Z 48 0 57 9 95 _ codes
Dim iCount As Byte
Dim iAsc As Byte
For iCount = 1 To Len(strInputString)
iAsc = Asc(Mid(strInputString, iCount, 1))
If iAsc >= 97 And iAsc <= 122 Then
ElseIf iAsc >= 65 And iAsc <= 90 Then
ElseIf iAsc >= 48 And iAsc <= 57 Then
ElseIf iAsc = 95 Then
Else
ValidateString = False
Exit Function
End If
Next iCount
ValidateString = True
End Function
' To allow user to validate password entry field
Public Function OnlyValidPass(KeyAscii As Integer) As Integer
If Not (KeyAscii >= 65 And KeyAscii <= 90) And Not (KeyAscii >= 97 And KeyAscii <= 122) And Not (KeyAscii >= 48 And KeyAscii <= 57) And Not (KeyAscii = 13 Or KeyAscii = 8) And Not KeyAscii = 32 And Not KeyAscii = 9 And Not KeyAscii = 46 Then
KeyAscii = 0
Beep
MsgBox "Not a valid char"
End If
OnlyValidPass = KeyAscii
End Function
' To allow user to insert only Numbers and Dots in the text field
Public Function OnlyNumericNDot(KeyAscii As Integer) As Integer
If Not (KeyAscii >= 48 And KeyAscii <= 57) And Not (KeyAscii = 13 Or KeyAscii = 8) And Not (KeyAscii >= 1 And KeyAscii <= 26) And Not KeyAscii = 46 Then
KeyAscii = 0
Beep
MsgBox "Only numbers are allowed", vbInformation, "Data Entry Error"
End If
OnlyNumericNDot = KeyAscii
End Function
' To allow user to insert only Numbers in the text field
Public Function OnlyNumeric(KeyAscii As Integer) As Integer
If Not (KeyAscii >= 48 And KeyAscii <= 57) And Not (KeyAscii = 13 Or KeyAscii = 8) And Not (KeyAscii >= 1 And KeyAscii <= 26) Then
KeyAscii = 0
Beep
MsgBox "Only numbers are allowed", vbInformation, "Data Entry Error"
End If
OnlyNumeric = KeyAscii
End Function
' To allow user to insert only character in the text field
Public Function OnlyChar(KeyAscii As Integer) As Integer
If (KeyAscii >= 48 And KeyAscii <= 57) Then
KeyAscii = 0
Beep
MsgBox "Only Characters are allowed", vbInformation, "Data Entry Error"
End If
OnlyChar = KeyAscii
End Function
' To Block characters to be entered in some places
Function InvalidChar(KeyAscii As Integer) As Integer
If Not (KeyAscii >= 65 And KeyAscii <= 90) And Not (KeyAscii >= 97 And KeyAscii <= 122) And Not (KeyAscii >= 48 And KeyAscii <= 57) And Not (KeyAscii = 13 Or KeyAscii = 8) Then
KeyAscii = 0
MsgBox "Not a valid char"
Beep
End If
InvalidChar = KeyAscii
End Function
' To validate Email
Public Function ValidateEmail(ByVal stremail As String) As Boolean
Dim intPos As Integer
On Error GoTo errval
If Not IsNull(stremail) Then
If Trim(stremail) = "" Then
ValidateEmail = True
Exit Function
End If
End If
intPos = InStr(1, stremail, "@")
If intPos = 0 Or intPos = 1 Then
ValidateEmail = False
Exit Function
End If
If InStr(intPos + 1, stremail, ".") = 0 Then
ValidateEmail = False
Exit Function
End If
ValidateEmail = True
Exit Function
errval:
ValidateEmail = False
End Function
' To Find Combo Box Data
Public Function FindComboData(ByVal cbo As ComboBox, ByVal ID As Integer) As Integer
Dim i As Integer
Dim b As Boolean
b = False
If ID > 0 Then
For i = 0 To cbo.ListCount - 1
If cbo.ItemData(i) = ID Then
b = True
Exit For
End If
Next
End If
If Not b Then
FindComboData = -1
Else
FindComboData = i
End If
End Function
' To Show row Color while Selecting VS Flex Grid Row
Public Function gridcolor(grd As VSFlexGrid) As Boolean
If grd.Rows = 1 Then
Exit Function
End If
Dim i As Integer
Dim lngrow As Long
Dim lngcol As Long
lngrow = grd.Row
lngcol = grd.Col
For i = 1 To grd.Rows - 1
grd.Cell(flexcpBackColor, i, 0, i, grd.Cols - 1) = vbWhite
Next
If grd.Cell(flexcpBackColor, lngrow, 0, lngrow, grd.Cols - 1) = &HC0E0FF Then
grd.Cell(flexcpBackColor, lngrow, 0, lngrow, grd.Cols - 1) = vbWhite
gridcolor = False
Exit Function
End If
If lngrow = 0 Then
Exit Function
Else
grd.Cell(flexcpBackColor, lngrow, 0, lngrow, grd.Cols - 1) = &HC0E0FF
gridcolor = True
End If
End Function
1 comment:
This is good Job Dude!!! Thanks
Post a Comment