Salad wrote:
[snip] [snip] [snip] [snip] [snip] [snip]
thank you both for your comments...
Here is the final function I wrote:
Public Function FMFEH(n) As Long
'form most frequent error handling
'On Error GoTo er
'-
Dim FRM As Form
Dim Ctl As Control
Dim S As String
Dim C As Long
Dim FldD As String
Dim FldN As String
Dim OK As Boolean
'-
FMFEH = True
Select Case n
Case 3201, 3314
S = FINTXT(307) & vbCr & vbLf & vbCr & vbLf
C = 0
If Not (SCFAF Is Nothing) Then
Set FRM = SCFAF
For Each Ctl In FRM.Section(0).Controls
If eCount("[ID]", "[T-TFC]", "[T-TFC]![T-TFD-ID]=" &
TabDctoID(Ctl.NAME, "T-TFD") & " AND [T-TFC]![T-TAB-ID]=" &
TabDctoID(FRM.Tag)) = 1 Then ' T-TFC = a table in which I store data about
the fields, here i check for an entry
If Ctl.Visible = True Then
If Ctl.Width > 0 Then
If NZZ(Ctl.Value) = False Then
Select Case Ctl.ControlType
Case acComboBox
If Ctl.LimitToList = True Then
OK = True
Else
OK = False
End If
Case acTextBox
If eLookup("[UNI]", "[T-TFC]", "[T-TFC]![T-TFD-ID]="
& TabDctoID(Ctl.NAME, "T-TFD") & " AND [T-TFC]![T-TAB-ID]=" &
TabDctoID(FRM.Tag)) = True Then ' T-TFC = a table in which I store data
about the fields' requirements (e.g. unique index combo)
OK = True
Else
OK = False
End If 'other stuff
Case Else
OK = False
End Select
Else
OK = False
End If
If OK = True Then
FldD = eLookup("[D]", "[T-TFC]", "[T-TFC]![T-TFD-ID]=" &
TabDctoID(Ctl.NAME, "T-TFD") & " AND [T-TFC]![T-TAB-ID]=" &
TabDctoID(FRM.Tag)) ' T-TFC = a table in which I store data about the
fields' names
If C > 0 Then
S = S & " AND ALSO "
C = C + 1
End If
S = S & FldD & vbCr & vbLf & vbCr & vbLf
Ctl.OnLostFocus = "=CRBAE(" & Ctl.BorderColor & ")"
Ctl.BorderColor = RGB(255, 0, 0)
End If
End If
End If
End If
Next Ctl
End If
msgbox S
FMFEH = False
Case 3022
msgbox "info about duplicate records"
FMFEH = False
Case Else
FMFEH = True
End Select
xt:
Exit Function
er:
FMFEH = True
Resume xt
End Function
===============================
and I add the following to each form
===============================
for each frm in ....
set frm = ..
set mdl = frm.module
x = 1
MDL.InsertLines x, "option compare database": x = x + 1
MDL.InsertLines x, "Option Explicit": x = x + 1
MDL.InsertLines x, "Private Sub Form_Error(DataErr As Integer, Response
As Integer)": x = x + 1
MDL.InsertLines x, " Response = FMFEH(DataErr)": x = x + 1
MDL.InsertLines x, "End Sub": x = x + 1
next frm