Function er_GetDisplayValue (sDataVal As String, axList() As ListItem, sDisplayVal As String)
Dim iMax As Integer
Dim i As Integer
Dim sTrimmedString As String
sTrimmedString = Trim(sDataVal)
iMax = UBound(axList)
For i = LBound(axList) To iMax - 1
If sTrimmedString = axList(i).DataVal Then
sDisplayVal = axList(i).DisplayVal
er_GetDisplayValue = True
Exit Function
End If
Next i
er_GetDisplayValue = False
sDisplayVal = sTrimmedString
End Function
Sub er_LoadList (ListCtrl As Control, ListItems() As ListItem)
Dim i As Integer
For i = 0 To UBound(ListItems) - 1
ListCtrl.AddItem ListItems(i).DisplayVal
ListCtrl.ItemData(ListCtrl.NewIndex) = i
Next
End Sub
Sub er_NewButton (Frm As Form, ds As Data, nNoRepos As Integer, bUpdateFailed As Integer)
bUpdateFailed = False 'MAR, MB2
'If er_CurrRowExists(ds) And ds.EditMode <> dbEditNone Then 'MAR line replaced
If ds.EditMode <> dbEditNone Then
er_DS_Update Frm, ds, nNoRepos, bUpdateFailed
End If
If Not bUpdateFailed Then 'MAR
ds.Recordset.AddNew
End If 'MAR
End Sub
Function er_NullValue (fld As Field) As Variant
Select Case fld.Type
Case DB_BOOLEAN
er_NullValue = 0
Case DB_BYTE
er_NullValue = 0
Case DB_INTEGER
er_NullValue = 0
Case DB_LONG
er_NullValue = 0
Case DB_CURRENCY
er_NullValue = 0
Case DB_SINGLE
er_NullValue = 0
Case DB_DOUBLE
er_NullValue = 0
Case DB_DATE
er_NullValue = ""
Case DB_TEXT
er_NullValue = ""
Case DB_LONGBINARY
er_NullValue = ""
Case DB_MEMO
er_NullValue = ""
End Select
End Function
Function er_ObjectSet (ds As Data) As Integer
Dim iMode As Integer
On Error GoTo ObjectSet_Handler
er_ObjectSet = True
' Try to cause an error by accessing the data control
If ds.EditMode = dbEditAdd Then iMode = 0 'no op
Exit Function
ObjectSet_Handler:
Select Case Err
Case 91
er_ObjectSet = False
Resume Next
Case Else
er_DisplayError (Err)
Resume Next
End Select
End Function
Function er_PreValidate (ds As Data, Action As Integer, Save As Integer) As Integer
er_PreValidate = False
Select Case Action
'Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST, DATA_ACTIONDELETE 'MAR removed
Case DATA_ACTIONMOVEFIRST To DATA_ACTIONMOVELAST
If ds.Recordset.RecordCount = 0 And Save = False Then
'Action = DATA_ACTIONCANCEL 'MAR removed
Save = False
er_PreValidate = True
End If
Case DATA_ACTIONDELETE
If ds.Recordset.RecordCount = 0 And Save = False Then
Action = DATA_ACTIONCANCEL
Save = False
er_PreValidate = True
End If
Case DATA_ACTIONUPDATE
If Save = False Then
Action = DATA_ACTIONCANCEL
er_PreValidate = True
End If
Case DATA_ACTIONBOOKMARK
If Save = False Then
er_PreValidate = True
End If
End Select
Exit Function
PreVal_Handler:
Select Case Err
Case 3021 ' Error: No current record
Beep
Resume Next
Case Else
er_DisplayError (Err)
Resume Next
End Select
End Function
Sub er_RestoreChangedFlags (axCtrl() As Control, abFlag() As Integer)
Dim iMax As Integer
Dim i As Integer
iMax = UBound(axCtrl)
For i = 0 To iMax - 1
axCtrl(i).DataChanged = abFlag(i)
Next i
End Sub
Sub er_SaveChangedFlags (axCtrl() As Control, abFlag() As Integer)
Dim iMax As Integer
Dim i As Integer
iMax = UBound(axCtrl)
For i = 0 To iMax - 1
abFlag(i) = axCtrl(i).DataChanged
Next i
End Sub
Sub er_SetEditMode (ds As Data)
On Error GoTo SetEditMode_Handler
If er_CurrRowExists(ds) And ds.EditMode = dbEditNone Then
ds.Recordset.Edit
End If
Exit Sub
SetEditMode_Handler:
Select Case Err
'Case 3197 ' Error: Data has changed, operation stopped
' Resume
Case Else
er_DisplayError (Err)
Resume Next
End Select
End Sub
Sub er_SetFieldToNull (fld As Field)
Select Case fld.Type
Case DB_BOOLEAN
fld = 0
Case DB_BYTE
fld = 0
Case DB_INTEGER
fld = 0
Case DB_LONG
fld = 0
Case DB_CURRENCY
fld = 0
Case DB_SINGLE
fld = 0
Case DB_DOUBLE
fld = 0
Case DB_DATE
fld = Date
Case DB_TEXT
fld = ""
Case DB_LONGBINARY
fld = ""
Case DB_MEMO
fld = ""
End Select
End Sub
Function er_SQLValue (ds As Data, sFldName As String)
Dim bQuotes As Integer
Dim sValue As String
Dim vValue As Variant
Select Case ds.Recordset(sFldName).Type
Case DB_TEXT
bQuotes = True
Case DB_MEMO
bQuotes = True
Case Else
bQuotes = False
End Select
If IsNull(ds.Recordset(sFldName)) Then
vValue = er_NullValue(ds.Recordset(sFldName))
sValue = vValue
Else
sValue = LTrim(RTrim(ds.Recordset(sFldName)))
End If
If bQuotes Then
sValue = "'" & sValue & "'"
End If
er_SQLValue = sValue
End Function
Function erwAddDisplayFieldTranslation (ctlData As Data, strFieldName As String, varValue As Variant, udtTranslateList() As TranslateItem, nListCount As Integer)
Function erwSetNewListField (ListCtrl As Control, DataCtrl As Data, FieldName As String, ListItems() As ListItem, bValidate As Integer, bNoClick As Integer)
Dim i As Integer
Dim ListIndex As Integer
Dim GStrIndex As Long
Dim FieldValue As String
Dim bRetVal
bRetVal = True
Err = 0
On Error Resume Next
ListIndex = ListCtrl.ListIndex
'If no list selection, see if typed in text is on list and select it if so