Max Wanadoo
max.wanadoo at gmail.com
Wed Jan 21 12:13:59 CST 2009
I would probably do something like this:
Private Sub EventSeatA001_BeforeUpdate(Cancel As Integer)
Dim str As String
Const conValid As String = "ARCPSN"
str = Me!ActiveControl
If InStr(conValid, str) = 0 Then
MsgBox "The valid choices are 'A' (available), 'R' (reserved),
'C'(chorus/cast), 'P' (pre-sale), 'S' (sold), and 'N' (not available)."
Me.ActiveControl.Undo
Cancel = True
Else
Call setseatbackcolour
End If
End Sub
If you are doing this for 100 plus controls you could put it all into one
single routine by setting the Form's OnKeyDown or Onkeypress to the function
The samples shown below are for a Suduko game I wrote some time back, but
show the method you could use. It avoid 81 different loads for code being
repeated for the 9x9 grid I was using
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Me!CtlKeyCode = KeyCode
Call pfKeyPress(KeyCode)
End Sub
Public Function pfKeyPress(intKeyCode As Integer)
On Error Resume Next
Dim ctlActive As Control, strname As String
Dim intRow As Integer, intCol As Integer
Set ctlActive = Screen.ActiveControl
strname = Me.ActiveControl.Name
intRow = Val(Mid(strname, 2, 1))
intCol = Val(Mid(strname, 4, 1))
If intKeyCode > 36 And intKeyCode < 41 Then
Select Case intKeyCode
Case conLeft
If intCol > 1 Then intCol = intCol - 1 Else intCol = 9: intRow =
intRow - 1
Case conRight
If intCol < 9 Then intCol = intCol + 1 Else intCol = 1: intRow =
intRow + 1
Case conUp
If intRow > 1 Then intRow = intRow - 1 Else intRow = 9: intCol =
intCol - 1
Case conDown
If intRow < 9 Then intRow = intRow + 1 Else intRow = 1: intCol =
intCol + 1
End Select
If intCol < 1 Then intCol = 9
If intCol > 9 Then intCol = 1
If intRow < 1 Then intRow = 9
If intRow > 9 Then intRow = 1
strname = "R" & CStr(intRow) & "C" & CStr(intCol)
Me(strname).SetFocus
End If
Call sShowHideTips
End Function
Max
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Bob Gajewski
Sent: 21 January 2009 04:29
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Question on preferred coding
Hi Folks
I have a subform with 100+ fields. I want to change the backcolor of each
field based upon the value entered by the user, after validation.
Both of the examples below seem to work fine. Is there a preferred way, or
is one better than the other?
Thanks
Bob Gajewski
Sample #1
_____
Private Sub EventSeatA001_BeforeUpdate(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 Sub
_____
Private Sub EventSeatA001_AfterUpdate()
SetSeatBackColor
End Sub
_____
Sample #2
_____
Private Sub EventSeatA001_BeforeUpdate(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
Else
SetSeatBackColor
End If
End Sub
_____
_____
P Please consider the environment before printing this e-mail
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com