473,780 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

make one form wait for another

1,277 Recognized Expert Top Contributor
I have a form that opens another form. I want the first form to wait for the form it opened to be filled out before it proceeds with processing what comes after the opening of the other form.

In this instance, a form used by the warehouse/shipping system is opening a form to get credit card information. After the credit card info is entered (it may be approved or not approved) I want to close the credit card form and update the order's status.

How can I make the first form wait for the second form's "done" or 'cancel' button to be clicked? I am working with Access 2003.

Thanks,
Jim
Mar 21 '08 #1
8 8319
FishVal
2,653 Recognized Expert Specialist
Hi, Jim.

Objects (including form objects) have a special mechanism to communicate - events.
The following code snippet illustrates a general approach. The scenario is the following:
  • [frmParent] has a button to open [frmChild]
  • [frmChild] has button [Done] which when pressed generates event handled in [frmParent]

[frmParent] module
Expand|Select|Wrap|Line Numbers
  1. Dim WithEvents frmChildForm As Form_frmChild
  2.  
  3. Private Sub btnOpenForm_Click()
  4.     DoCmd.OpenForm "frmChild"
  5.     Set frmChildForm = Forms!frmChild
  6. End Sub
  7.  
  8. Private Sub frmChildForm_Done(strReturn As String)
  9.     MsgBox "Child form has done something" & vbCrLf & "And says: " & strReturn
  10. End Sub
  11.  
[frmChild] module
Expand|Select|Wrap|Line Numbers
  1. Event Done(strReturn As String)
  2.  
  3. Private Sub btnDone_Click()
  4.     RaiseEvent Done("I have done")
  5. End Sub
  6.  
Enjoy OOP.

Kind regards,
Fish
Mar 21 '08 #2
missinglinq
3,532 Recognized Expert Specialist
I believe the short answer here would be to open the second form in Dialog mode, which does exactly what you want:

DoCmd.OpenForm YourFormName, , , , , acDialog


Linq ;0)>
Mar 21 '08 #3
ADezii
8,834 Recognized Expert Expert
I believe the short answer here would be to open the second form in Dialog mode, which does exactly what you want:

DoCmd.OpenForm YourFormName, , , , , acDialog


Linq ;0)>
I'm with Linq on this one:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmChild", acNormal, , , acFormEdit, acDialog
  2.  
  3. 'by opening the frmChild Window in Dialog Mode, its Modal and Popup
  4. 'properties are set to True, all procesing from this point on will
  5. 'be suspended until frmChild is closed
  6. '...
  7. 'will never execute until frmChild is closed
  8. Msgbox "Done in frmChild"
Mar 22 '08 #4
FishVal
2,653 Recognized Expert Specialist
Sure Linq's suggestion is simpler and doesn't touch programming aspects that may be new or complicated for OP.

But the child form is expected to return some information (credit card number and user choice as for action type) to the parent form. When opening form in Dialog mode code execution in Parent form proceeds after Child form is closed and thus inaccessible. So the options are the following.
  • global variable - IMHO not the best possible solution
  • child form calls method/property in parents form module
  • child form raises event handled in parent form module
  • something else I cannot figure so far

Regards,
Fish
Mar 22 '08 #5
ADezii
8,834 Recognized Expert Expert
Sure Linq's suggestion is simpler and doesn't touch programming aspects that may be new or complicated for OP.

But the child form is expected to return some information (credit card number and user choice as for action type) to the parent form. When opening form in Dialog mode code execution in Parent form proceeds after Child form is closed and thus inaccessible. So the options are the following.
  • global variable - IMHO not the best possible solution
  • child form calls method/property in parents form module
  • child form raises event handled in parent form module
  • something else I cannot figure so far

Regards,
Fish
Good points, FishVal! I was under the assumption that once the Child Form was closed, the data, if entered, would persist in the form of being written to a Table related to the Order itself. If that were the case, it could be easily retrieved. Don't mind me, just off on another tangent again. (LOL).
Mar 22 '08 #6
jimatqsi
1,277 Recognized Expert Top Contributor
Thanks to everyone for their advice. I'm so glad to have gotten more than one way to solve this.

However, being under the gun, I came up with another solution while I was waiting for your great ideas. I put an endless loop with a DoEvents in it after opening the child form. Then I changed the "Done" button on the child form to update an invisible checkbox to True. I break out of the endless loop when that checkbox on the child form becomes True and I close the child from from within the parent.

That seems to have solved the problem. Does it cause any problems I don't know about?

Thanks very much!

Jim
Mar 23 '08 #7
ADezii
8,834 Recognized Expert Expert
Thanks to everyone for their advice. I'm so glad to have gotten more than one way to solve this.

However, being under the gun, I came up with another solution while I was waiting for your great ideas. I put an endless loop with a DoEvents in it after opening the child form. Then I changed the "Done" button on the child form to update an invisible checkbox to True. I break out of the endless loop when that checkbox on the child form becomes True and I close the child from from within the parent.

That seems to have solved the problem. Does it cause any problems I don't know about?

Thanks very much!

Jim
DoEvents occupies valuable CPU time and passes control to the Operating System where it processes Events in it Queue. You must be very careful when you use DoEvents within an Event Procedure. If by any chance the procedure is executed again from a different part of your code before the first call returns; this could cause unpredictable results
Mar 23 '08 #8
FishVal
2,653 Recognized Expert Specialist
I agree with ADezii.

Using DoEvents requires many nuances to be kept in mind.
For example you need to prevent frmChild closing by any way except you've implemented.
Closing it via CloseWindow button will result in fault in frmParent loop.
Moreover closing it with Alt-F4 crashes Access completely. ;)

Regards,
Fish.

P.S. And I never liked that 100% CPU usage indicated in Task Manager when DoEvents loop is running. Looks very suspicious.
Mar 24 '08 #9

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

Similar topics

1
2220
by: David Gagné | last post by:
Hello, My C# solution is composed of 2 projects, a class library project and a Windows application project. The window in one project calls the DLL in the other. That's ok. Now, to better test the solution I would like to create a new Windows application project in that solution so that my 2 other projects are not impacted by this third project. Now this new project would contain the startup Form from which I could open my Form in the...
1
1331
by: Belee | last post by:
1. I have developed an MDI app with a status bar in C#. I want the current MDIChild active form text or caption to be written in one of the MDI Form's status bar panels. 2. What is the best way of passing information from one form to another in C#.
5
1730
by: Tamir Khason | last post by:
Is it possible managed detect that one form inaplicationcontext is above other ? -- Tamir Khason You want dot.NET? Just ask: "Please, www.dotnet.us "
4
1559
by: Mike | last post by:
Hi, I need to pass a value from one Web Form to another. In Form #1 I have set up a web control (hyperlink) that in its "Transfer" property contains the name of the Web Form to be loaded. How can I read the listIndex of a Listbox in Form #1 when the Form#2 is loaded? Thanks Mike
4
9863
by: jaYPee | last post by:
I know how to open a form from another form. Say open form2 from form1 using a command button. But my problem is everytime I clicked the button it open again another instance of that form. here's my code Dim Course As New Course Course.Show() My question is on how to prevent a form from opening again if it is
2
1712
by: PM | last post by:
I have a VB.NET question about ListViews and Forms. I have a listview with records. I want a user to be able to double-click on a record, and have a subform come up with detailed information about that particular record. This user can then make edits. The problem is - I do not know how to pass information from a form to another form. I don't want to use Public variables if possible. Basically, How do I pass the value of the...
6
6336
by: Leszek | last post by:
Hi. I wrote a script: function zmiana(ile){ while(document.getElementById('accomp').childNodes.length>1){ ostatni=document.getElementById('document.dane.accomp').lastChild; document.getElementById('document.dane.accomp').removeChild(ostatni);
8
37735
by: C.Joseph Drayton | last post by:
Hi All, I am calling a PHP script that does an operation then sends back a result. I want JavaScript to wait until that result has been recieved. I am using the following code. What can I do to stop it from generating a 'Too much recursion' error? function WaitForData() {
4
4355
by: MichaelK | last post by:
Hello. I have all data already collected on the current page? I want to open another window with the form, fill the fields and submit that form. So basically the question is how can I fill all fields and submit the form on another window. Regards, Michael
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.