[AccessD] Referencing forms as objects

William Benson (VBACreations.Com) vbacreations at gmail.com
Mon Aug 1 13:21:04 CDT 2011


Can you do something with a click event and a timer? i.e., click event
starts a timer, and if another click event occurs while timer is under a
certain increment from there, treat the second click like a double-click?

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Dan Waters
Sent: Monday, August 01, 2011 12:44 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Referencing forms as objects

Thanks John!

I will try this.  First, I have to solve the problem of no double-click
event available for a combobox on a winform in visual studio.

Dan

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Monday, August 01, 2011 11:29 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Referencing forms as objects

Dan, here ya go.

Notice that in order to do this I had to:

1) Dimension a form object WithEvents in the header of the calling form.
This tells the calling form that it has a class (form in this case) that may
be raising events.

2) Build one or more event sink.  This takes the object dimensioned in step
1 above and sinks one (or more) events that that object is raising.

3) In the object raising the event I have to define the event that it will
raise in the header of that object (the modal form in this case).  This
tells the compiler that this object is capable of raising at least one
event.

4) Raise the event wherever needed.  This actually causes the event to fire
and transfers data of event parameters are defined.

These 4 steps are always required to use events.

Only classes can raise events.  Only classes can sink events.  Forms are
classes, ergo forms can sink events (we already know that) but forms can
also raise events.

In the calling form:

'Header
'
'Define an object (a form) that we are going to sink events for '
Public WithEvents frmDiaryExtensionReason As Form_frmDiaryExtensionReason

'
'event sink
'This is where the data comes back from the modal form '
Private Sub frmDiaryExtensionReason_evExtendDate(dte As Date,
strExtendReason As String)

     	txtExtendReason.Value = strExtendReason
	txtExtendDate.value = dte
	me.dirty = false
End Sub

'The combo that causes the unbound form to open Private Sub
cboCloseReason_AfterUpdate()
     Select Case cboCloseReason.column(0)
     Case 2      'Rescheduled - needs to be copied then the original closed
         DoCmd.OpenForm "frmDiaryExtensionReason"
         Set frmDiaryExtensionReason = Forms("frmDiaryExtensionReason")

In the modal form:

'this defines the event that the form will raise '
Public Event evExtendDate(dte As Date, strExtendReason As String) '
Private blnValidDate As Boolean

Private Sub cmdCancel_Click()
     DoCmd.Close acForm, Me.Name
End Sub

Private Sub cmdExtendDate_Click()
     If blnValidDate Then
         'Validate that they put something in the comment
         If Len(txtExtendReason.Value) Then
             '
	    'This is where the event is raised and data sent of to someone
else
             RaiseEvent evExtendDate(txtExtendDate.Value,
txtExtendReason.Value)
             DoCmd.Close acForm, Me.Name
         Else
             MsgBox "No reason was entered"
             txtExtendReason.SetFocus
         End If
     Else
         MsgBox "The date entered is not valid"
         txtExtendDate.Value = ""
         txtExtendDate.SetFocus
     End If
End Sub

'Validate that the entry is a date
Private Sub txtExtendDate_AfterUpdate()
Dim dte As Date
     On Error Resume Next
     dte = txtExtendDate.Value
     If Err Then
         blnValidDate = False
     Else
         blnValidDate = True
     End If
End Sub


John W. Colby
www.ColbyConsulting.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list