Shamil Salakhetdinov
shamil at users.mns.ru
Thu Dec 29 01:42:59 CST 2005
Joe,
you have to use custom class modules - here is one of many possible
solutions (error handling omitted):
' ========== cut here =============
'+ form module
Option Compare Database
Option Explicit
Private mfrm As CForm
Private Sub Form_Load()
Set mfrm = New CForm
mfrm.Init Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
mfrm.Dispose
Set mfrm = Nothing
End Sub
'-form module
' ========== cut here =============
'+ custom class module CForm
Option Compare Database
Option Explicit
Private Const className As String = "CForm"
Private mfrm As Access.Form
Private mcolControls As Collection
Private mfDisposed As Boolean
Public Sub Init(ByRef rfrm As Access.Form)
Dim ectl As Access.Control
Dim txt As CTextBox
Set mfrm = rfrm
Set mcolControls = New Collection
For Each ectl In rfrm.Controls
If ectl.ControlType = acTextBox Then
Set txt = New CTextBox
txt.Init ectl
mcolControls.Add txt
End If
Next ectl
End Sub
Public Sub Dispose()
Dim etxt As CTextBox
Dim lngIdx As Long
If mfDisposed = False Then
With mcolControls
If .Count > 0 Then
For lngIdx = .Count - 1 To 1 Step -1
Set etxt = mcolControls.Item(lngIdx)
etxt.Dispose
mcolControls.Remove lngIdx
Next lngIdx
End If
End With
Set mcolControls = Nothing
Set mfrm = Nothing
mfDisposed = True
End If
End Sub
'- custom class module CForm
' ========== cut here =============
'+ custom class module CTextBox
Option Compare Database
Option Explicit
Private Const className As String = "CTextBox"
Private WithEvents mtxt As Access.TextBox
Private Const eventProcedure As String = _
"[Event Procedure]"
Private mfDisposed As Boolean
Public Sub Init(ByRef rtxt As Access.TextBox)
Set mtxt = rtxt
With mtxt
.OnGotFocus = eventProcedure
.OnLostFocus = eventProcedure
mtxt_LostFocus
End With
End Sub
Public Sub Dispose()
On Error Resume Next
If mfDisposed = False Then
If Not mtxt Is Nothing Then
Set mtxt = Nothing
End If
mfDisposed = True
End If
End Sub
Private Sub mtxt_GotFocus()
With mtxt
.BackColor = RGB(255, 255, 255)
.SpecialEffect = 1
End With
End Sub
Private Sub mtxt_LostFocus()
With mtxt
.BackColor = RGB(255, 255, 0)
.SpecialEffect = 2
End With
End Sub
'- custom class module CTextBox
' ========== cut here =============
Shamil
----- Original Message -----
From: "Joe Hecht" <jmhecht at earthlink.net>
To: "'Access Developers discussion and problem solving'"
<accessd at databaseadvisors.com>
Sent: Thursday, December 29, 2005 8:00 AM
Subject: [AccessD] Code help Please
> I still do not understand public modules
>
>
>
> I have the following code for a set of text boxes
>
>
>
> Private Sub txtFirstName_GotFocus()
>
> Dim lngwhite As Long
>
> lngwhite = RGB(255, 255, 255)
>
> Me.txtFirstName.BackColor = lngwhite
>
> Me.txtFirstName.SpecialEffect = 1
>
> End Sub
>
>
>
> Private Sub txtFirstName_LostFocus()
>
> Dim lngyellow As Long
>
> lngyellow = RGB(255, 255, 0)
>
> Me.txtFirstName.BackColor = RGB(255, 255, 0)
>
> Me.txtFirstName.SpecialEffect = 2
>
> End Sub
>
>
>
> How do I make modules that will trigger as each text box
> gets and loses focus?
>
>
>
> Thanks
>
>
>
> Joe Hecht
>
> jmhecht at earthlink.net
>
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com