[AccessD] Request for help with Function

Bob Gajewski rbgajewski at roadrunner.com
Wed Jan 14 00:46:15 CST 2009


Hello Friends
 
I have a form that contains 184 one-character text fields (EventSeatA001,
EventSeatA002, etc) - seats in an auditorium. All fields are defaulted to
"A".
 
I need to check the value that the user inputs, and if an invalid character
was entered, I want to display an error message and return the field to the
value from before it was changed.
 
I have the following code in the _BeforeUpdate CBF for each of the 184
fields, and it works just fine.
 
Code Sample 1
===============================
If Me.ActiveControl <> "A" And Me.ActiveControl <> "R" And Me.ActiveControl
<> "C" And Me.ActiveControl <> "P" And Me.ActiveControl <> "S" And
Me.ActiveControl <> "N" Then
    MsgBox "The valid choices are 'A' (available), 'R' (reserved), 'C'
(chorus/cast), 'P' (pre-sale), 'S' (sold), and 'N' (not available)."
    Cancel = True
    Me.ActiveControl.Undo
End If

===============================
 
However, I would prefer to put this validation into a Function and just call
it in each _BeforeUpdate. This would make maintenance SO much easier. This
is where I am struggling. I wrote the Function code and made the call in the
_BeforeUpdate ...
 
Code Sample 2
===============================
Private Function isValidStatus()
Dim Cancel As Integer
If Me.ActiveControl <> "A" And Me.ActiveControl <> "R" And Me.ActiveControl
<> "C" And Me.ActiveControl <> "P" And Me.ActiveControl <> "S" And
Me.ActiveControl <> "N" Then
    MsgBox "The valid choices are 'A' (available), 'R' (reserved), 'C'
(chorus/cast), 'P' (pre-sale), 'S' (sold), and 'N' (not available)."
    Cancel = True
    Me.ActiveControl.Undo
End If
End Function
===============================
 
Code Sample 3
===============================
Private Sub EventSeatA001_BeforeUpdate(Cancel As Integer)
isValidStatus (Me.ActiveControl.Value)
End Sub
===============================
 
... and the validation works fine, but as soon as I click on [OK] on the
message box, I get a system error message:
 
Code Sample 4
===============================
Run-time error 13:
 
Type mismatch
===============================
 
If anyone can point me in the right direction, I would very appreciative.
 
Thanks,
Bob Gajewski
 
 
P Please consider the environment before printing this e-mail 
 



More information about the AccessD mailing list