Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1081421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:10:00+00:00 2026-05-16T22:10:00+00:00

I have a form in MS Access which has an image. The image has

  • 0

I have a form in MS Access which has an image. The image has an Click event which opens a modal form. The modal form has an OK and Cancel button. When you click the OK button, an event is supposed to fire which tells the main form which button was clicked. (This is to simulate the DialogResult functionality in C#). However, the code in the event handler never runs.

The modal form has the following in the general declarations:

Public Event OnDialogBoxClose(NewRecordID As Long, DialogResult As DialogResults)

and the following code where the OK button is clicked:

RaiseEvent OnDialogBoxClose(NewHardwareBaseItemID, dlgresBtnOKClicked)

The main form has the following in the general declarations:

Dim WithEvents RespondQuickAddClose As Form_qckfrmHardwareBaseItemCreate

and the following event handler:

Private Sub RespondQuickAddClose_OnDialogBoxClose(NewRecordID As Long, DialogResult As DialogResults)

    MsgBox "Responding to closing of the dialog box" 'Never happens
    Me.Requery

End Sub

Can someone explain why the event handler is never called?
Thanks!

Background:

The purpose of all this is to allow a modal dialog box to add an entry, then return the ID of the entry back to the main form to set the value of controls. For instance, imagine you are filling out an insurance form, and you need to select a brand of car this is not there. You click on an icon which pops up with the modal dialog box to allow you to add the car brand. Then when you click OK, it takes you back to the insurance form and selects the brand of car you just created.

This follows an example I found here:
http://database.itags.org/ms-access-database/80292/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:10:00+00:00Added an answer on May 16, 2026 at 10:10 pm

    You’re making your life way too complicated by applying concepts from a different development environment to Access VBA. While VBA does support WithEvents/RaiseEvent, there’s no reason to get that complicated here.

    The usual way to work with dialogs in Access is that instead of closing them, you hide them. This allows the code after the form was open to run while leaving the values in the form available for use in that code.

    Sample code in the OnOpen event of a report that opens a form for collecting values to filter the report:

      Private Sub Report_Open(Cancel As Integer)
        DoCmd.OpenForm "dlgDateRange", , , , , acDialog, "ThisYear"
        If IsLoaded("dlgDateRange") Then
           With Forms!dlgDateRange
             If .Tag = "Cancel" Then
                Cancel = True
             Else
                Me.Filter = "[InvoiceDate] Between #" & !txtStart & "# AND #" & !txtEnd & "#"
                Me.FilterOn = True
                Me!lblDateRange.Caption = StrConv(Trim(("from " + varZLStoNull(Format(!txtStart, "mm/dd/yyyy"))) _
                    & (" to " + varZLStoNull(Format(!txtEnd, "mm/dd/yyyy")))), vbProperCase)
             End If
           End With
           DoCmd.Close acForm, "dlgDateRange"
        End If
      End Sub
    

    The dialog form has two command buttons, CONTINUE>> and CANCEL. The CANCEL button sets the form’s tag to “Cancel” and sets the form’s .Visible property to False. The CONTINUE>> button does nothing but set the form’s .Visible property to False. Clicking either of those buttons allows the code to continue on the line after the form is open with the acDialog switch.

    My philosophy is to make the dialogs as stupid as possible. The calling code has to know what it’s looking for in the forms (i.e., you need to know the names of the controls you’re reading data out of), but that could be gotten around by adding customer properties to the form. But then you have to know the property names, so you’ve just moved the ball.

    I have also implemented this kind of thing by wrapping the dailog form in a class module, and then the calling context simply initializes an instance of the class and then pulls the values out of it at the appropriate time. But that’s actually more complicated that the approach above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: I built an Access form with a subform (which
I have an Access form where each record has some info that is computed
I have form area in my view. If I click button A , I
I have a form in C# that has a button that, when clicked, I
I have asp.net form that contains fields. When I access this window, my javascript
I have subclassed Form to include some extra functionality, which boils down to a
I have form that displays several keywords (standard set of choice lists that changes
I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have a form with some radio buttons that are disabled by default. When
I have a form with many input fields. When I catch the submit form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.