Solved

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

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

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 58
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 34

Expert Comment

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

Author Closing Comment

by:chtullu135
ID: 40590097
Thanks Rey
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

691 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