473,698 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close Current Form, Open a New One and vice-versa

Microblitz
40 New Member
Two weeks (Well about 8 hours actually) into writing VBA code and I've run up against a problem.

This is the senario;

----
I have a "Main" form in which an entry on a drop down selects one of three types of test.

The type of test designates the type of form used to enter the data.

Therefore when my drop down select type 2 from its field or if the user uses the navigation to move through the records, the system must look at the drop down and see if it = the number 2 if it does then close the "Main" form and open the "Superform" (The name is abitrary).

Likewise if the user moves off the "Superform" using the nave buttons or changing the state of the drop down the reverse is applied, the Superform closes and Main opens.
-----

Sounds simple right?

So we need to look at the Main form after its been selected using the nav buttons examine the drop down see if its a "2" and close main, open Superform.
OR
If the state of the dropdown changes to a "2" then close main, open superform
Else
do nothing

This is the code I'm using on the superform when the drop down state is changed which works fine.

Expand|Select|Wrap|Line Numbers
  1. Private Sub CBO_MachineSpecification_AfterUpdate()
  2.  
  3. If ([MachineSpecification] = 2) Then
  4.  DoCmd.OpenForm "Superform", acNormal, , , acFormEdit, acWindowNormal
  5.   DoCmd.Close acForm, "Main", acSaveYes
  6. Else
  7.   DoCmd.OpenForm "Main", acNormal, , , acFormEdit, acWindowNormal
  8.     DoCmd.Close acForm, "Superform", acSaveYes
  9. End If
  10. End Sub
  11.  
If I reuse this code and add this to "Main"'s 'Current' event, so that it checks everytime the record is changed I get the following error

Run-Time error '2585' (This action cannot be carried out while processing a form or report event.) as the Main form attempts to be closed.

Huh? So Close takes no account of the state of the item it's closing? It doesn't wait until the form has completed its housekeeping before trying to shut it down?

Where am I going wrong?
Jul 26 '10 #1
9 14213
patjones
931 Recognized Expert Contributor
Just wondering if there is any particular reason that you want to close out the main form when the secondary form opens up. I've got a similar situation in a couple of my databases at work and usually allow the main form to just stay open in the background.

That being said, I can say that in the past I have had problems trying to close a form from within it's own module.

If you attach this code to an event other than On Current, does the same problem result?

Pat
Jul 26 '10 #2
Microblitz
40 New Member
@zepphead80
There are two forms of test both require basically the same data however they are not entirely identical, and they are entered in different order.

The idea is to use a field in the database to change the format of the form (hide one open another).

The only event that seems to trigger when the inbuilt navigation is performed (in 2007) is on current.
Jul 26 '10 #3
Microblitz
40 New Member
Even more wierdness.

I had a brainwave perhaps I had answered my own question and instead of closing the form, just use its visible switch to hide it.

So I wrote this to deal with the first case senario (Record 1 who's MachineSpecific ation is = 2)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. Form_Main.Visible = True
  3. Form_Superform.Visible = False
  4. If ([MachineSpecification] = 2) Then
  5. Form_Main.Visible = False
  6. Form_Superform.Visible = True
  7. End If
  8. End Sub
  9.  
It unhides the "Superform" but doesnt hide the "Main" form. There is no logical reason why it shouldn't!


I'm beginning to think I should go back to assembly language, at least that IS logical!
Jul 26 '10 #4
NeoPa
32,569 Recognized Expert Moderator MVP
Hiding and showing forms is not only more reliable, it also performs more smoothly. There is a certain overhead opening forms (though not always noticeable to the naked eye).

I suspect your current problem is related to trying this from within the Load event procedure. Try Open instead.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open()
  2.     Form_Superform.Visible = ([MachineSpecification] = 2)
  3.     Form_Main.Visible = (Not Form_Superform.Visible)
  4. End Sub
Jul 26 '10 #5
Microblitz
40 New Member
@NeoPa
That doesnt do anything different to my original code even when added to the open form event.

PS that is some seriously wierd logic youre using there. Talk about code readability...n ot (Pun intended!)

Double click click Main to start the DBMS
Both the Main and the Superform display as open.
I ran the code in debug and as soon as it hits the endsub at the end of your code it reopens the Main form.

Could this have somthing to do with the focus?
Jul 26 '10 #6
NeoPa
32,569 Recognized Expert Moderator MVP
If that doesn't help I'm going to need to know how you structure your forms.

Are the two forms both opened by a third, or is one opened by the other?
Jul 26 '10 #7
Microblitz
40 New Member
@NeoPa
Each form opens the other, so the psuedo is;

Load form
Check form type required from machineSpecific ation field.

If machineSpecific ation = 2 load(unHide) form2 Unload(Hide)for m1 else load form1 unload(Hide) form2

Of course form2 has the reverse.

I managed to get this going last night using your hide code but now it has created another problem.

When I swap forms it looses the previous forms position becomming one record out of sync.

I'm going to need to figure out how to detect which Nav button is press (forward/backward) and transfer the current record + 1 (or minus 1)to the next form.

Ive considered dumping the inbuilt Nav buttons but is need the general search it provides.

(This is access 2007 by the way)
This thread is getting off topic so Ill open another one for this query. Thanks for the help.
Jul 27 '10 #8
NeoPa
32,569 Recognized Expert Moderator MVP
No worries.

Feel free to post a link in here to the new thread and I'll go there as a priority.
Jul 27 '10 #9

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

Similar topics

3
19229
by: Kimelia | last post by:
I want to create something like wizard, which will ask one question and proceed to the next question. So, it's like showing Form A (Question 1), then when the user press "Next" button, I want to close Form A (Question 1), and show Form B (Question 2). Sorry to ask if this is too simple, as I am still learning C#. Thanks and have a nice day.
2
2904
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open. Although the child form has a close button (with java script) if the user navigates the parent form to another form the child form is still open. Just wondering if there is a way to close the child form when the user navigates away with the parent...
5
13541
by: prob | last post by:
I would like to acheive the following VB6 code in VB.NET Code in the Form1 - Button1_Click Dim obj1 as new form2 obj1.Prop = myprop obj1.show unload me
4
4450
by: DraguVaso | last post by:
Hi, I want a Login-form that, once the username and password are validated, opens a new Form (of the 'main'-application), and closes itself. I tryed it like this: putting the following code in the click-event of the login-button of my Login-form: Dim frmAG As New frmAgent frmAG.Show() Me.Close()
3
5931
by: Karan | last post by:
I am calling finalize when form2 loads and deactivates form1 which closes form1. However, same thing is not happening in form2 because finalize is already called. Does anybody has solution to it. This code works well for splash screen. I searched alot on net for codes but they don't work. for example- (1) Public Sub CloseForm(formType As System.Type) For Each oForm as System.Windows.Forms.Form in me.MdiParent.MdiChildren If...
4
9574
by: ghadley_00 | last post by:
Hi, Can anyone recommend a piece of VBA code I could attach to a button in a MS Form form that will close the current form and bring the switchboard to foreground. I'm trying to integrate a form of buttons into the way the switchboard gets used. Best wishes, George Hadley
2
12146
by: MLH | last post by:
Suppose that code running on FormB is moving the focus around on FormA to various textbox controls on FormA - Which form is the current form during this process? Is it FormA, which has the focus. Or is it FormB, whose code is doing the work?
4
1836
by: Jacko7289 | last post by:
Hi, I've got a form (SearchForm1) which searches the student number using the surname, given name, date of birth. Once the student number is shown i want the user to click a button which will close the search form (SearchForm1) and then open the survey form (SurveyForm1). In short i want a button which closes the current form (permanently) and opens another form at the same time. Any suggetions is very much appreciated. Cheers, Jacko7289
3
3008
by: godhulirbalaka | last post by:
Dear Sir/Madam, I am new vb 6.0 user. I am developing Shop Management Program. I have a main form with buttons and menus. when i click any button then respective form is open. I want to set a command by which when i click a button then respective form will open and when i click another button then previous opened form will close and new form will open. that means at a time only one form will active with the main form. Please note that i dont...
6
3690
by: dotnetnovice | last post by:
Hi everybody. I need some help in c# forms problem which is i have three forms naming main form,form1 & form2. main form is the mdiparent of both form1 and form2. i also have a toolstrip in my main form which includes option close current frm and close all. what i need is when i click the close current form option the form opened state(either form1 or form2) close down. suppose currently form 2 is currently open in the main form and i...
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9027
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
8895
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
7725
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
6518
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
5860
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
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.