Consulting

Results 1 to 6 of 6

Thread: Adding Classes WithEvents to Form

  1. #1

    Adding Classes WithEvents to Form

    Cross Posted at http://stackoverflow.com/questions/1...ms-access-form and at http://social.msdn.microsoft.com/For...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...

    [vba]

    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

    [/vba]
    Any ideas?
    Last edited by mantooth29; 07-12-2013 at 10:03 AM.

  2. #2
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    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.

  4. #4
    VBAX Newbie
    Joined
    Jul 2013
    Location
    New York
    Posts
    3
    Location

    reply

    Glad to know about it,thanks for sharing with us

  5. #5
    VBAX Newbie
    Joined
    Jul 2013
    Location
    New York
    Posts
    3
    Location

    reply

    Wonderful forum

  6. #6
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •