Solved

How to return the value of the ok button on a dialog form to the parent form

Posted on 2015-02-04
5
123 Views
Last Modified: 2015-02-04
I've created a dialog form that is called from a parent form.  When the user clicks either the OK or Cancel button on the dialog form, I want to return that to the calling form.  I want to indicate to the calling form what button was pressed

dim response as variant

docmd.openform "Test" ,,,,acDialog

response = 'Value of returned response
0
Comment
Question by:chtullu135
5 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 40589856
Where have you declared reponse?

If you declared it as public in a standard module (Insert>Module) then the code behind both forms could access it.

So you could add code to the buttons on the dialog form that sets the value of response to the appropriate value.
0
 
LVL 57
ID: 40589859
Two ways:

1. Create a hidden control on the form, then set that and hide the form when they click close or cancel.   Calling code can then check that control (and any others), then close the form.

2. Use a global variable or a collection to hold the value, let the form close when OK or cancel is clicked.

Jim.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40589895
in the click event of the OK button, place

private sub cmdOK_Click()
TempVars.Add "Response", "OK"
docmd.close acform, me.name
end sub


in the click event of the Cancel button, place

private sub cmdCancel_Click()

TempVars.Add "Response", "Cancel"
docmd.close acform, me.name
end sub

docmd.openform "Test" ,,,,acDialog
msgbox tempVars!Response

'no need to declare variables
0
 
LVL 33

Expert Comment

by:Norie
ID: 40589898
Totally forgot about TempVars.
0
 

Author Closing Comment

by:chtullu135
ID: 40590097
Thanks Rey
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

777 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