PDA

View Full Version : Adding Classes WithEvents to Form



mantooth29
07-12-2013, 09:18 AM
Cross Posted at http://stackoverflow.com/questions/17619633/adding-classes-withevents-to-ms-access-form and at http://social.msdn.microsoft.com/Forums/en-US/4b0e610f-7d3e-42dc-a584-05eb4987b230/adding-classes-withevents-to-ms-access-form

I'm having a hard time trying to incorporate some custom classes I have created into an Access Form using WithEvents. The custom classes I want to use are not tied to Access specifically (not a form class).

I know that Access Forms are not like standard VBA UserForms, but is there a way to hook into Events of custom classes with them?

ie...



Option Compare Database
Option Explicit

Private WithEvents FileSearch As C_FileSearch 'Custom Class - Form Global

Private Sub Button_Click()

Set FileSearch = New C_FileSearch

FileSearch.Init "C:\", "*", ".*"

FileSearch.FindFiles

If FileSearch.FilesFound.Count = 0 Then

Debug.Print "No Files!"

Else

Dim fil As Scripting.File

For Each fil In FileSearch.FilesFound

Debug.Print fil.Name

Next fil

End If

End Sub

'The Event below shows up in Events drop down list in a VBA User Form, but not with an Access Form
Private Sub FileSearch_FileFound(FileName As String, File_Extension As String, File_Path As String, FileObj As Scripting.File, Action As FSFileActions, Created As Date, Modified As Date, Accessed As Date, FileAttributes As VbFileAttribute)

If FileName Like "*MyFile*" Then Action = fsIncludeAndContinue Else Action = fsSkip

End Sub


Any ideas?

HiTechCoach
07-14-2013, 02:20 PM
it is getting replies here: http://social.msdn.microsoft.com/Forums/en-US/4b0e610f-7d3e-42dc-a584-05eb4987b230/adding-classes-withevents-to-ms-access-form

mantooth29
07-14-2013, 02:59 PM
Thanks for keeping an eye on this. I just replied over there. Unfortunately the article describes designing in the opposite direction I need to.

The other reply was describing how a person should be able to do this like with any other class or VBA UserForm module.

However, at this time it appears that you cannot add an external Custom Class WithEvents in an Access form which is very surprising.

monika1990
07-28-2013, 08:05 PM
Glad to know about it,thanks for sharing with us

monika1990
07-28-2013, 08:06 PM
Wonderful forum

mantooth29
07-30-2013, 06:57 AM
I hope my previous post does not lead anyone down the wrong path. You can add custom classes with events to Access forms. This is posted in the other thread at MSDN, but intellisense was not picking up my events, until I manually pasted the signature for one of them into the Access Form module. From there it was able to recognize the rest throughout the project.