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?
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?