473,406 Members | 2,843 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,406 software developers and data experts.

How to Open a Form Synchronously

759 512MB
Hope this is the window for question.

My question:
I have two forms (say FORM_1 and Form_2)
As you know (more of you), in Excel, I can open FORM_2 from FORM_1 using code (in FORM_1):

FORM_2.Show()
If I use vbModal mode (FORM_2.Show(vbModal) the next line in FORM_1 code will not be executed until FORM_2 is closed.

The question is: Can I obtain the same effect in Access VBA ? I wish to avoid to continue code execution in FORM_1 before I close FORM_2.

I use 2007 version of MS Office.

Thank you in advance !
Apr 10 '11 #1
12 3190
NeoPa
32,556 Expert Mod 16PB
Forms in Access also have a property .Modal which allows them to take full control.
Apr 10 '11 #2
Mihail
759 512MB
Thank you for your reply, NeoPa.
Unlike in Excel VBA, the .Modal in Access only stop the form to lost focus.

Expand|Select|Wrap|Line Numbers
  1. Private sub Open_FORM_2
  2.      On Error .......
  3.      .............
  4.      DoCmd OpenForm FORM_2 ....
  5.      First line AFTER DoCmd
  6.      ............
  7. End sub
I do not wish that first line after DoCmd to be executed while FORM_2 is open. Unfortunately this happened.
Maybe somewhere is a setting ?!?!?

Thank you again for the reply.
Apr 11 '11 #3
Mihail
759 512MB
I find the "solution":
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm stDocName, , , , , acDialog
But work only one level.

If I have n forms FORM_1, FORM_2, ... FORM_k ... FORM_n and, in each form, this code:
-------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Me.Visible = FALSE
  2.    DoCmd.OpenForm FORM_k+1, , , , , acDialog
  3. Me.Visible = TRUE
-------------------------------------------
where k is the current form (k = 1 ... n-1)

then the instruction "Me.Visible = TRUE" in FORM_k is not executed until I close FORM_k+1. That's OK. But, once I close the "k+1" form, the instruction
Expand|Select|Wrap|Line Numbers
  1.     "Me.Visible = TRUE"
will be executed for all k, k-1, k-2, ... 1 forms.

Why ? How stop this cascade ? Is it possible ?

Thank you in advance.
Apr 11 '11 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Now I have not tried your exact setup, but just want to add that IF the form K+1 is allready open in design mode, it can be forced open by DoCmd.OpenForm, however the Dialog/modal property does not always take in such a case. So when your testing, ensure that all your forms are closed. (Its good practise anyway to ensure all forms are closed, before testing/modifying code)
Apr 11 '11 #5
Mihail
759 512MB
TheSmileyCoder, thank you for reply.
I do that. Sometimes I close the Access application before (re)test the code. It works (in both cases) as I say.
My last "solution" is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDefinire_Click()
  2. On Error GoTo Err_cmdDefinire_Click
  3.  
  4.         Me.Visible = False
  5.     DoCmd.OpenForm "10_Localitati", , , , , , Me.Name
  6.  
  7. Exit_cmdDefinire_Click:
  8.     Exit Sub
  9.  
  10. Err_cmdDefinire_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_cmdDefinire_Click
  13. End Sub
  14.  
This is in FORM_k in order to open FORM_k+1".


And, in FORM_k+1 I have:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. Dim frm As Form
  3.     For Each frm In Application.Forms
  4.         If frm.Name = Me.OpenArgs Then
  5.             frm.Visible = True
  6. Exit sub
  7.         End If
  8.     Next frm
  9. End Sub
  10.  
It seems work OK. But is not what I wish.
I wish that run code in FORM_k AFTER I close FORM_k+1 (i e to refresh FORM_k informations). "Me.visible = TRUE" is MINIMUM what I need.

Now is necessary to manual refresh the FORM_k:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdRefreshForm_Click()
  2. On Error GoTo Err_cmdRefreshForm_Click
  3.  
  4.     DoCmd.RunCommand acCmdRefresh
  5.  
  6. Exit_cmdRefreshForm_Click:
  7.     Exit Sub
  8.  
  9. Err_cmdRefreshForm_Click:
  10.     MsgBox Err.Description
  11.     Resume Exit_cmdRefreshForm_Click
  12.  
  13. End Sub
Thank you again for reply. Maybe we (all) can find a solution. I google the web and there are many other posts on this subject but no one can find a true solution.
Apr 11 '11 #6
Mihail
759 512MB
Update to previous post:
I wish to kill Bill Gates.

The code in previous post work fine until... the FORM_k+1 is resized or moved. After that the OpenArgs become... empty. Why ? Maybe Bill Gates know.

So, in order to use the OpenArgs in the CLOSE event is necessary to declare a variable at the module level:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3. Dim MeOpenArgs
  4.  
  5. then:
  6.  
  7. Private Sub Form_Load()
  8.     MeOpenArgs = Me.OpenArgs
  9. End Sub
  10.  
  11. then:
  12.  
  13. Private Sub Form_Close()
  14. Dim frm As Form
  15.     For Each frm In Application.Forms
  16.         If frm.Name = MeOpenArgs Then
  17.             frm.Visible = True
  18. Exit Sub
  19.         End If
  20.     Next frm
  21. End Sub
Apr 11 '11 #7
TheSmileyCoder
2,322 Expert Mod 2GB
Hi again

I have tried to create a form and open it while passing a openarg. I tried resizing it, moving it, requery it, and setting the visible False/True, but I was not able to "loose" the openArgs. So not sure why you are experiencing that. What access version are you using?

I also tried creating a form, and have it open a form, which opened a form.....until I had 5 open forms. Each form had a close button and when I clicked the close button, my next line of code (after the Docmd.Openform) would run as intended.

I have no idea why you are getting the results you are.
Apr 11 '11 #8
Mihail
759 512MB
I use MS Office 2007.
It is the first time when I write a "seriously" code for Access. But I write hundred lines for Excel and the keywords work like the help files say. I don't understand too what happen now. I reinstall Office but no results. It work the same.

I close my forms using CLOSE BUTTON from CONTROL BOX.
Where you place the code for close form ? In the form CLOSE event or under the OnClick event of your CLOSE BUTTON ?

I place the code under the FORM close event. Tomorrow I'll try to use an button to close my forms.

Thank you very much for reply.
Apr 11 '11 #9
TheSmileyCoder
2,322 Expert Mod 2GB
Well I didn't really have any code in my Close event. I just made a button which closes the form, but I could as well have used the X of the form itself. I will see if my results are different in a Ac2007 version when I have the chance.
Apr 11 '11 #10
Mihail
759 512MB
Thank you !
My private address is ** Edit - email address removed in accordance with rules and for member protection **

You are much "older" than me here (on this forum) so you can decide better where you wish to help me. (Hope you understand what I wish to say because my english is very specialized. I learn from the computers help files).

Thank you again.
Apr 11 '11 #11
NeoPa
32,556 Expert Mod 16PB
Just like Smiley, I find that what you're reporting is not what I see on my systems. I don't use Access 2007 I admit, but I'd be surprised if it worked so differently from all the other versions.

I understand that your English is not too strong. You're doing well in the circumstances (Much better than I could handle Romanian). Please note though, that you must use CODE tags when posting code. Already too many posts updated for you.

Let us know how you get on though. Clearly you are clever enough to progress with this, but it's strange that you have unexpected results from your tests.
Apr 12 '11 #12
Mihail
759 512MB
Hi all

No progress on this topic.
The code do not stop in the FORM_k+1.
More, if I open the form with acDialog option, the form loose the sizable property and my forms MUST BE sizable.

So, I use the last "solution" I post and I decide to not waste anymore my time in this direction.

Thank you very much for yours help.
Apr 14 '11 #13

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

Similar topics

3
by: Stanley J Mroczek | last post by:
I have tried this with no luck. What i want is to show the selected item on the first post. the selected item is NY but the first in the list shows as selected. If Page.IsPostBack = False Then...
2
by: nooneinparticular | last post by:
I sat down last night and decided to try and teach myself something about programming in C++. I have always had an interest in it, so I went for it. This is what I have to show for my efforts. ...
4
by: Theron NightStar | last post by:
I am trying to teach myself c++. This is the first program I have ever written that might have an practical use to me. I rather proud of it since like implied - I have no real knowledge of c++. ...
0
by: tshad | last post by:
This is just a question on why this is happening. I have an HttpModule that is using the BeginRequest event. I noticed that when I load my page the first time, this event is not called, but if...
1
by: Scott F K Hooper | last post by:
I have an aspx page that I want to use to collect info and create session variables before navigating to another aspx page to use the new session vars. Ie, consider the following page,...
1
by: mark starnes | last post by:
Hi everyone, this is my first post to this group, so please be gentle. I've written a class which, when I attempt to pickle, gives the error: *** RuntimeError: maximum recursion depth exceeded...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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.