Solved

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

Posted on 2015-02-04
5
127 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

808 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