-
Notifications
You must be signed in to change notification settings - Fork 0
/
modFunctions.bas
223 lines (193 loc) · 5.76 KB
/
modFunctions.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Attribute VB_Name = "modFunctions"
Option Explicit
Public Sub AppendAND(ByRef filter As String)
If filter <> Empty Then
filter = filter & " AND "
End If
End Sub
Public Function AddToCollection(col As Collection, Item As String) As Boolean
AddToCollection = False
If Not Exists(col, Item) Then
col.Add Item, Item
AddToCollection = True
End If
End Function
Public Function Exists(col As Collection, Index As String) As Boolean
Dim o As Variant
On Error GoTo Error
o = col(Index)
Error:
Exists = o <> Empty
End Function
Public Function DoubleValue(strValue As String)
If Len(strValue) <> 0 Then
DoubleValue = CDbl(strValue)
Else
DoubleValue = 0
End If
End Function
Public Function ValidateTextBoxDouble(txBox As textbox, parentForm As Form)
On Error GoTo err:
DoubleValue txBox.text
ValidateTextBoxDouble = True
Exit Function
err:
modMain.LogStatus "The value inserted is not valid", parentForm
txBox.text = ""
txBox.SetFocus
ValidateTextBoxDouble = False
End Function
Public Function ValidateTextDouble(text As String, parentForm As Form)
On Error GoTo err:
DoubleValue text
ValidateTextDouble = True
Exit Function
err:
modMain.LogStatus "The value inserted is not valid", parentForm
ValidateTextDouble = False
End Function
Public Sub SelectAll(ByRef txtBox As textbox)
txtBox.SelStart = 0
txtBox.SelLength = Len(txtBox)
End Sub
Public Function UpCase(ByRef KeyAscii As Integer)
UpCase = Asc(UCase(Chr(KeyAscii)))
End Function
''''''''''''''''''''''''''''''''''
''' Combobox related functions '''
''''''''''''''''''''''''''''''''''
Public Sub LoadCombo(Table As String, combo As ComboBox, _
field As String, Optional valueField As String)
ExecuteSql "Select * From " & Table
combo.Clear
If (valueField <> Empty) Then
While Not rs.EOF
combo.AddItem (rs.Fields(field))
combo.ItemData(combo.NewIndex) = rs.Fields(valueField)
rs.MoveNext
Wend
Else
While Not rs.EOF
combo.AddItem (rs.Fields(field))
rs.MoveNext
Wend
End If
'If strDefault <> Empty Then
' combo = strDefault
'End If
End Sub
Public Function ComboEmpty(ByRef combo As ComboBox, _
Optional strip As Variant, _
Optional Index As Integer) _
As Boolean
If combo.ListIndex = -1 Then
ComboEmpty = True
MsgBox "Please select an option from the list", vbExclamation
If Index <> Empty Then
'strip.SelectedItem = strip.Tabs(Index)
End If
combo.SetFocus
Else
ComboEmpty = False
End If
End Function
Public Function NoRecords(lstView As ListView, Optional Prompt As String) As Boolean
If lstView.ListItems.Count = 0 Or lstView.SelectedItem Is Nothing Then
If Prompt <> Empty Then
MsgBox Prompt, vbExclamation
End If
NoRecords = True
Else
NoRecords = False
End If
End Function
Public Function RcrdId(Table As String, Optional Identifier As String, Optional FldNo As String) As String
Dim RcrdNo As Integer
ExecuteSql "Select * from " & Table & " order by " & FldNo & " ASC"
If rs.EOF = False Then
rs.MoveLast
RcrdNo = rs.Fields(FldNo) + 1
Else
RcrdNo = 1
End If
If Identifier <> Empty Then
RcrdId = Identifier & RcrdNo & Format(Date, "mm")
Else
RcrdId = RcrdNo
End If
End Function
'''''''''''''''''''''''''''''''''''''''''
Public Sub SearchShow(Table As String, fieldToSearch As String, itemToSearch As String)
With frmSearch
.Search Table, fieldToSearch, itemToSearch
.Show vbModal
End With
End Sub
Public Function ValBox(Prompt As String, Icon As Image, Optional Title As String, _
Optional Default As Double, _
Optional Header As String = "Value Box") As Double
'With frmValue
' If Title <> Empty Then
' .Caption = Title
' Else
' .Caption = App.Title
' End If
' .lblHeader.Caption = StrConv(Header, vbUpperCase)
' .imgIcon.Picture = Icon.Picture
' .lblPrompt.Caption = Prompt
' .Default Val(Default)
' .Show vbModal
' ValBox = Val(.txtValue.Text)
' Unload frmValue
'End With
End Function
Public Function TextBoxEmpty(ByRef stext As textbox, Optional TabObject As Variant, Optional TabIndex As Integer) As Boolean
If Trim(stext) = Empty Or stext.text = " / / " Then
TextBoxEmpty = True
MsgBox "You need to fill in all required fields", vbExclamation
If TabIndex <> Empty Then
'TabObject.SelectedItem = TabObject.Tabs(TabIndex)
End If
stext.SetFocus
Else
TextBoxEmpty = False
End If
End Function
Public Function TextBoxNumberEmpty(ByRef textbox As textbox) As Boolean
'if the input is not a numeric then true
If IsNumeric(textbox.text) = False Then
TextBoxNumberEmpty = True
MsgBox "The field requires a numeric value.", vbExclamation
textbox.SetFocus
SelectAll textbox
Else
TextBoxNumberEmpty = False
End If
End Function
Private Sub SaveDetection(Reference As String, Title As String, Description As String, Table As String)
ExecuteSql2 "Select * from " & Table
rs2.AddNew
rs2.Fields!record_no = Val(RcrdId(Table, , "record_no"))
rs2.Fields!Reference = Reference
rs2.Fields!war_type = Title
rs2.Fields!Description = Description
rs2.Update
End Sub
Public Function ExecErr(Prompt As String, _
Optional PromptFld As String, _
Optional Table As String, _
Optional RcrdFld As String, _
Optional RcrdStr As String) As String
Dim Rcrds As String
If Table <> Empty Then
ExecuteSql "Select * from " & Table & " where " & RcrdFld & " = '" & RcrdStr & "'"
While Not rs.EOF
Rcrds = Rcrds & rs.Fields(PromptFld) & "; "
rs.MoveNext
Wend
ExecErr = "Error: " & Prompt & vbNewLine & vbNewLine & _
"Related Records: " & Rcrds
Else
ExecErr = Prompt
End If
End Function