Solved

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

Posted on 2015-02-04
5
116 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
Comment Utility
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

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
Totally forgot about TempVars.
0
 

Author Closing Comment

by:chtullu135
Comment Utility
Thanks Rey
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now