Solved

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

Posted on 2015-02-04
5
128 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
[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
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

726 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