-
Notifications
You must be signed in to change notification settings - Fork 3
/
M_omControlFunctions.def
76 lines (61 loc) · 2.3 KB
/
M_omControlFunctions.def
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
Option Compare Database
Option Explicit
Public Sub IfNullOrEmpty(ctrl As Control, Optional UseDefaultValue As Boolean = True)
If omStringFunctions.IsNullOrEmpty(ctrl) Then
If UseDefaultValue And NotIsNullOrEmpty(ctrl.DefaultValue) Then
SetDefaultValue ctrl
Else
ctrl = ctrl.OldValue
End If
End If
End Sub
Public Sub SetDefaultValue(ctrl As Control)
Dim vDate As Variant
If omStringFunctions.NotIsNullOrEmpty(ctrl) Then
Exit Sub
End If
vDate = Replace(Replace(Nz(ctrl.defaultValue, ""), Chr(34), ""), "#", "")
ctrl = IIf(IsDate(vDate), vDate, ctrl.defaultValue)
End Sub
Public Function IsFormOpen(FormName As String) As Boolean
On Error GoTo IsFormOpen_Error
IsFormOpen = (Forms(FormName).Name = FormName)
Exit Function
IsFormOpen_Error:
IsFormOpen = False
End Function
Public Function GetOpenForm(FormName As String) As Form
If IsFormOpen(FormName) Then
Set GetOpenForm = Forms(FormName)
End If
End Function
Public Function NotInList(ctrl As Control, ObjectName As String, idFieldName As String, valueFieldName As String, NewData As String, Optional OpenEdit As Boolean = False, Optional ParentFieldName As String = "", Optional ParentData As Variant = Null) As Integer
Dim rs As New ADODB.Recordset
Dim Id As Long
If MsgBox("Nieuw item: " & NewData & " toevoegen?", vbYesNo) = vbYes Then
rs.Open omStringFunctions.GetEnglishPlural(ObjectName), CurrentProject.Connection, adOpenForwardOnly, adLockOptimistic
rs.AddNew
rs(valueFieldName) = NewData
If NotIsNullOrEmpty(ParentFieldName) Then
rs(ParentFieldName) = ParentData
End If
rs.update
Id = rs(idFieldName)
rs.Close
Set rs = Nothing
If OpenEdit Then
DoCmd.OpenForm ObjectName & "_Edit", , , "Id=" & Id, acFormEdit, acDialog
End If
End If
If Id = 0 Then
NotInList = acDataErrContinue
Else
ctrl.value = Id
NotInList = acDataErrAdded
End If
End Function
Public Sub Edit(ctrl As Control, ObjectName As String, Optional idFieldName As String = "Id")
If NotIsNullOrEmpty(ctrl.value) Then
DoCmd.OpenForm ObjectName & "_Edit", , , idFieldName & "=" & ctrl.value, acFormEdit, acDialog
End If
End Sub