473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Returning Data from Modal Form

Hello,

This may seem really stupid, but what's the best way to return data from a Modal form??

It seems that Access uses a different Forms library to the other MS apps, and does not have the usual .Show member.

I have a form I have set as Modal in its Form properties. I have a Class module with properties (i.e. my data object). The form has a private instance of this class, and as options are selected and set on the form, the data is set in the object.

The form is initially called from some VBA code, and I want to be able to retrieve that object in the form after the user hits run.

Access appears to have only one way to open and display a modal form, using DoCmd.Open, where the acDialog option can be used to prevent code from continuing on until the form is closed.

The problem with this is of course that the single line command effectively loads a new instance of the form, runs it, and then closes and unloads it straight away when the user closes it, without ever creating a referrable instance in the code.

This means no data can be passed to the form before showing, and cannot be retrieved after the form has been closed.

With other VBA apps I could load the form, call some properties on the form first to populate the form, show it, and the code would not advance until it was hidden. But the form would not unload from memory, so the data was still retrievable afterwards.

It seems while Access has got the Load/Unload options, it only has the .Visible property, which of course does not stop the code from advancing until the form is hidden, so the calling code tries to continue on.

The only workaround I can think of is to have a DoEvents loop after the form becomes visible checking for a flag on the form to be set before continuing, with code on the form setting the flag on the press of a button. This seems like a clunky workaround to me.

Any help is appreciated.

Regards,
Rob.
Jun 15 '08 #1
7 17601
RuralGuy
375 Expert 256MB
Have you tried using global variables or maybe passing a control name in the OpenArgs argument?
Jun 15 '08 #2
FishVal
2,653 Expert 2GB
....
Access appears to have only one way to open and display a modal form, using DoCmd.Open, where the acDialog option can be used to prevent code from continuing on until the form is closed.
.....
Fortunately it is not the only option.
You may make form modal, anytime you like, setting its "Modal" property to True.

Regards,
Fish

P.S. You may find interesting this thread.
Jun 16 '08 #3
Fortunately it is not the only option.
You may make form modal, anytime you like, setting its "Modal" property to True.

Regards,
Fish

P.S. You may find interesting this thread.
Yes, I was aware of that, as I stated in my post. The problem is that simply setting that does not stop the code.

Have you tried using global variables or maybe passing a control name in the OpenArgs argument?
As much as I hate global variables, I suspect this is about the only way of doing this. I had hoped that the data manipulation could be encapsulated within the code and passed around correctly.

Thanks for your responses.

Regards,
Rob.
Jun 16 '08 #4
FishVal
2,653 Expert 2GB
Yes, I was aware of that, as I stated in my post. The problem is that simply setting that does not stop the code.
What for you want to stop code execution?

Kind regards,
Fish
Jun 16 '08 #5
What for you want to stop code execution?

Kind regards,
Fish
The reason for having the form be Modal is that it is for the user to supply options to a process.

The sequence goes:

1) Import data from sources.
2) Do some analysis and calculations
3) *Present user with options based on results*
4) Do output based on user options.

So I need to open the form to set data for the rest of the process to use.

The problem is that the options made available to the user will depend on the analysis, and the output will depend on the user options. So I need to be able to pass information to and from the form when opend/closed, but not allow the code in the background to carry on until the options have been chosen.

The alternative I've just considered is having an intermediate "save table" that makes the input and output available to both ends, but this is messy to me.

I'm planning on using a static property of the class object to make it available internally in the object calling the form, but accessible by the form without having to be passed the explicit instance of the object.

I know this would work in other languages, so I'll try it here.

Regards,
Rob.
Jun 16 '08 #6
FishVal
2,653 Expert 2GB
You may handle second form event in the first form module or you may call first form method/property from the second form module.

Regards,
Fish
Jun 16 '08 #7
ADezii
8,834 Expert 8TB
How about?
  1. Opening the Form in Hidden Mode
  2. Assign values to Form Fields while the Form is Hidden
  3. Make the Form visible at the appropriate time
    Expand|Select|Wrap|Line Numbers
    1. DoCmd.OpenForm "Form2", acNormal, , , acFormEdit, acHidden
    2.  
    3. Forms!Form2![Field3] = "Bart"
    4. Forms!Form2![Field4] = "Simpson"
    5.  
    6. Forms!Form2.Visible = True
  4. As far as retaining Form values once it is closed, how about assigning Field values to a Public Array for later, easy retrieval?
Jun 16 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Matt | last post by:
I want to post the form data (http://server/page1.asp) to a modal dialog window (http://server/modaldialog.asp) with a desired height 200px by width 200px. Here's my attempts and problems: ...
2
by: Matt | last post by:
I reposted this question because I really want to accomplish this task. Please advise!! I want to post the form data (http://server/page1.asp) to a modal dialog window...
4
by: Job Lot | last post by:
How would I send information from DataGrid on the main form of the application to a modal popup form and then pass any changes to the data back to the main form and database when the popup form was...
2
by: Matt | last post by:
I want to know how to submit the form data to a modal dialog window? The following is page1.asp, and when the user clicks submit button, it will post the form data to page2.asp by opening a new...
4
by: Kyralessa | last post by:
In Access 2000, I have a base form with a ListBox of conference registrants. In the form's declarations section I include Dim f as Form To add a registrant I'm doing this: Set f = New...
8
by: J. Black | last post by:
Hello everyone - I've been developing an incident tracking and reporting system for an emergency services outfit that I work with part time. It's going well, except for one fly in the ointment....
2
by: Cheryl | last post by:
Hi, I have encounter a problem.Language use is C#. I would like to open a new window (is a modal window, where I m not able to switch from parent window after this window is open)from the parent...
1
by: Curious Trigger | last post by:
Hi there, programming with Visual Studio 2005 and ASP.NET 2.0 I want to open a modal dialog from Default.aspx. I searched the net and many newsgroups but I couldn't find any solution. First I...
7
by: Dan Tallent | last post by:
I have an application I'm working on where one form will open another. This newly opened form needs to return a value based on the users actions. My forms are not modal. I have seen discussions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.