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. -
Private Sub CBO_MachineSpecification_AfterUpdate()
-
-
If ([MachineSpecification] = 2) Then
-
DoCmd.OpenForm "Superform", acNormal, , , acFormEdit, acWindowNormal
-
DoCmd.Close acForm, "Main", acSaveYes
-
Else
-
DoCmd.OpenForm "Main", acNormal, , , acFormEdit, acWindowNormal
-
DoCmd.Close acForm, "Superform", acSaveYes
-
End If
-
End Sub
-
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?
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
@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.
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) -
Private Sub Form_Load()
-
Form_Main.Visible = True
-
Form_Superform.Visible = False
-
If ([MachineSpecification] = 2) Then
-
Form_Main.Visible = False
-
Form_Superform.Visible = True
-
End If
-
End Sub
-
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!
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. - Private Sub Form_Open()
-
Form_Superform.Visible = ([MachineSpecification] = 2)
-
Form_Main.Visible = (Not Form_Superform.Visible)
-
End Sub
@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? 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?
@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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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...
|
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
|
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()
|
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...
| |
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
|
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?
|
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
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |