?
Solved

MS Access parent form event not received by VB? OCX control

Posted on 2010-09-06
2
Medium Priority
?
618 Views
Last Modified: 2012-05-10
I am recreating an OCX UserControl in VB6 I did many years ago.  It is basically a series of buttons to be used in an MS Access 2003 form.  The UserControl provides standardized functions to navigate the records, add, edit, delete, save and undo.  It is also aware of the application and security context.

As I said, I developped and used such a control many years ago but I don't have the source code anymore.

I created the UserControl and dropped it in the Access Form.  Clicking on the buttons will raise the events and perform the appropriate action.

However, the control does not received the form's events.  

The code snippet from the control below illustrates that I declared a module variable withEvents to hold the form reference.  This variable is initialized in the Show event handler of the userControl.  It is used by the cmdAdd_click event to move the form to a new record (this is working).  The form also received the events raised by the control (such as BeforeAdd and AfterAdd).  However, the m_ParentForm_Current event is never fired (as any other form events I've tried).

I think it may be some configuration on either the VB6 or Access side.

I compiled the userControl in both Apartment and Single threaded modes without difference in the result.


Dim WithEvents m_ParentForm As Access.Form
Dim m_AccessApp As Access.Application


Private Sub UserControl_Show()
    
    If Ambient.UserMode Then
        Set m_ParentForm = Extender.Parent.object
        Set m_AccessApp = m_ParentForm.Application
    end if

end sub


Private Sub cmdAdd_Click()
    Dim wCancel As Boolean
    
    wCancel = False
    RaiseEvent BeforeAdd(wCancel)
    
    If Not wCancel Then
        m_AccessApp.DoCmd.GoToRecord acDataForm, m_ParentForm.Name, acNewRec
        RaiseEvent AfterAdd
    End If

End Sub


Private Sub m_ParentForm_Current()

    MsgBox "Current"
    
End Sub

Open in new window

0
Comment
Question by:ragoran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 33612939
<<I think it may be some configuration on either the VB6 or Access side. >>
  In Access, unless the property sheet reads "[Event Procedure]", the event won't fire even if sunk.  I have some code here to run through forms and add that if you want.
JimD.
0
 
LVL 14

Author Comment

by:ragoran
ID: 33613224
YES!

I knew it was something simple but could not remember.

Thanks Jim

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question