[AccessD] Abstract question

Michael R Mattys mmattys at rochester.rr.com
Sun Feb 11 10:14:00 CST 2007


Based upon Shamil Salakhetdinov's previous work using WithEvents
in Access, I created a simple spreadsheet form ...

'Template Form Attached
Application.LoadFromText acForm, "Spreadsheet", "C:\Spreadsheet.txt"

'-----clsSpreadsheet-----
Private WithEvents Form As Form
Private mcolControls As New Collection
Private mobjSelfRef As Object
Private mblnTerminateCalled As Boolean

Public Sub Init(ByRef rfrm As Access.Form)
    DeepsAttach rfrm
End Sub

Public Sub Terminate()
    Dim obj As Object
    If mblnTerminateCalled = False Then
       For Each obj In mcolControls
         On Error Resume Next
         obj.Terminate
         Err.Clear
       Next
       mblnTerminateCalled = True
    End If
End Sub

Private Sub DeepsAttach(ByRef rfrm As Access.Form)
    Set Form = rfrm
    Set mobjSelfRef = Me
    Form!lblHwnd.Caption = Form.hwnd
    Dim ctl As Access.Control
    Dim objTxt As clsSSTextBox
    For Each ctl In Form.Controls
        If TypeOf ctl Is Access.TextBox Then
            Set objTxt = New clsSSTextBox
            objTxt.Init ctl
            mcolControls.Add objTxt
        End If
    Next
End Sub

'-----clsSSTextbox-----
Private WithEvents mtxt As Access.TextBox
Private msngLastX As Single
Private msngLastY As Single
Private mlngBackColor As Long
Private mstrLastCtlName As String

Public Sub Init(ByRef rtxt As Access.TextBox)
    Set mtxt = rtxt
    mlngBackColor = mtxt.BackColor
    mtxt.OnEnter = "[Event Procedure]"
    mtxt.OnExit = "[Event Procedure]"
    mtxt.OnMouseMove = "[Event Procedure]"
    mtxt.OnGotFocus = "[Event Procedure]"
    mtxt.OnLostFocus = "[Event Procedure]"
End Sub

Private Sub mtxt_Enter()
    mlngBackColor = mtxt.BackColor
    mtxt.BackColor = 16776960
End Sub

Private Sub mtxt_Exit(Cancel As Integer)
    mtxt.BackColor = mlngBackColor
End Sub

Private Sub mtxt_GotFocus()
    mtxt.BackColor = vbRed
End Sub

Private Sub mtxt_Lostfocus()
    mtxt_Exit 0
End Sub

Private Sub mtxt_MouseMove(Button As Integer, Shift As Integer, x As Single, 
y As Single)
  On Error GoTo mtxt_MouseMove_Err

'  If msngLastX <> X Or msngLastY <> Y Then
'    If mstrLastCtlName <> mtxt.Name Then
        mtxt.SetFocus
'    End If
'  End If
  msngLastX = x
  msngLastY = y
  mstrLastCtlName = mtxt.Name

mtxt_MouseMove_Err:
End Sub

Michael R. Mattys
MapPoint & Access Dev
www.mattysconsulting.com 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Spreadsheet.txt
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20070211/66ecae9b/attachment-0001.txt>


More information about the AccessD mailing list