Connecting Tech Pros Worldwide Help | Site Map

making an error more meaningful....

windandwaves
Guest
 
Posts: n/a
#1: Nov 13 '05
Hi,

I am trying to make errors a bit more meaningful for my users.

I am trying to fix error 3201 where there is a missing field in a form.

If I do not do any error trapping, then I get

You cannot add or change a record because a related record is required in
table 'my table name'.

All I wanted to do is to change my table name to something more meaningful
in onerror event. However, when I access the message there, I get:

You cannot add or change a record because a related record is required in
table '|'.

Does anyone know how this works?

TIA

- Nicolaas


easyrider@cityu.edu
Guest
 
Posts: n/a
#2: Nov 13 '05

re: making an error more meaningful....


I am new to this group, but here are a few links that I found when I
searched on "error 3201", hopefully they might help.

http://groups-beta.google.com/group/...bf0685a81b7cd8

this person was nice enough to post their solution: (close to the
bottom, same error statement you recieved.)
http://groups-beta.google.com/group/...4f5503179589d4

Salad
Guest
 
Posts: n/a
#3: Nov 13 '05

re: making an error more meaningful....


windandwaves wrote:
[color=blue]
> Hi,
>
> I am trying to make errors a bit more meaningful for my users.
>
> I am trying to fix error 3201 where there is a missing field in a form.
>
> If I do not do any error trapping, then I get
>
> You cannot add or change a record because a related record is required in
> table 'my table name'.
>
> All I wanted to do is to change my table name to something more meaningful
> in onerror event. However, when I access the message there, I get:
>
> You cannot add or change a record because a related record is required in
> table '|'.
>
> Does anyone know how this works?
>
> TIA
>
> - Nicolaas
>
>[/color]
Since I'm not sure where it's called...
In the forms OnError event, maybe something like
If Dataerr = 3021 then
or in a OnError event
If Err.Number = 3021 then
and then put in the error message of your own fashion. Will that work?

3021 seems to be about a current record not being available.
windandwaves
Guest
 
Posts: n/a
#4: Nov 13 '05

re: making an error more meaningful....


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


Closed Thread