473,387 Members | 1,569 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,387 software developers and data experts.

How do I close form if not used?

675 512MB
I want to open a form, let's call it fSelect, with some optional choices on it. If the operator makes a choice, that choice is saved to a control on the main form, and fSelect is closed.

However, I would like to close fSelect if the operator ignores it and continues to work on the main form.

fSelect cannot be Dialog, i.e. modal, or operator cannot ignore it.
LostFocus for fSelect doesn't seem to fire.
Deactivate fires, but attempts to close the form gets:
Expand|Select|Wrap|Line Numbers
  1.    Run-time error '2585'
  2.    This action can't be carried out while processing a form or report event.
In other words, I can't close fSelect while processing the Deactivate event.

How can I close this form (fSelect) if it is opened and displayed, but not used?
Sep 22 '10 #1

✓ answered by malcolmk

use the DoCmd.Close acForm, "formname"
in the "active" event on the main form so that after selecting your option on form fselct when the next form opens insert the command into that forms "active" event.
so eg. form1 make aselection and call form2, when form2 opens its "active" event closes form1.

17 4812
DoCmd.Close acForm, "formname"
Sep 22 '10 #2
gnawoncents
214 100+
Do you want it to close after a certain amount of time, or when they begin to interact with the main form, or on some other trigger?
Sep 22 '10 #3
OldBirdman
675 512MB
malcolmk -
Thanks, but this is what I'm doing now, with the result of Run-time error '2585' so the form doesn't close. Trapping the error hasn't worked either. I don't know what to do after it errors. Attempting again to close the form gets me into an infinite loop, or course.

gnawoncents -
I want to close the form ASAP (As Soon As Possible). I don't like timers because they're either too slow (long time) or they are too fast, and take action when operator is distracted.

The form has one control (Listbox named lbxSelect). I've tried setting lbxSelect.SetFocus and triggering the close on LostFocus. This event never fires if focus goes to the main form.

I've tried giving the form focus with Me.SetFocus or Me!SetFocus, but this doesn't fire either, probably because there is an enabled, visible control on the form.

Form_Deactivate fires, but then Run-time error '2585' when I try to execute the Close.

I will trigger off of ANY event that fires and permits me to close the form.
Sep 22 '10 #4
Mariostg
332 100+
I use the following function for a different purpose but maybe it could help. Maybe you could run it when your Main form gets the focus and if the proposed function returns true then close the form...
Expand|Select|Wrap|Line Numbers
  1. Function IsLoaded(ByVal strFormName As String) As Boolean
  2.  
  3. Const conObjStateClosed = 0
  4. Const conDesignView = 0
  5.  
  6. If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
  7.     If Forms(strFormName).CurrentView <> conDesignView Then
  8.         IsLoaded = True
  9.     End If
  10. End If
  11.  
  12. End Function
  13.  
  14.  
Sep 22 '10 #5
ChipR
1,287 Expert 1GB
You haven't adequately described when you want the form to close. Unless there is an event that you want to trigger the closing of the form, you would use the timer to determine how long it had not been used.

Why not let the user open the form modal if they need it?
Sep 22 '10 #6
OldBirdman
675 512MB
The main form's GotFocus doesn't fire when a control is clicked. What fires is the control's GotFocus. This would entail using the GotFocus event for every control on the form, and checking for IsLoaded.
Normal navigation around the form would have this called almost continually for what was (I hoped) an infrequently used form.
Sep 22 '10 #7
ChipR
1,287 Expert 1GB
What's the purpose of the form? When does it open?
Sep 22 '10 #8
OldBirdman
675 512MB
The form consists of a listbox lbxSelect. The rowsource is an SQL statement with OpenArgs as the WHERE condition. There is only 1 column in lbxSelect.

Main program is a log. Many of the textboxes have similar entries. For example, the textbox txtReason might have 'Stop Service' or 'Complaint' or 'Dispute Bill' or 'Change' or something completely unique. I want, when this box is entered (tab or mouse) to have the list of common entries displayed for selection, or if operator chooses, they may ignore completely and enter something else, like '2nd request, cancel order'.
I originally tried a hidden listbox which I could set to .Visible. Works fine, when Clicked or LostFocus it is rehidden. Takes too much space vertically as it cannot cross a record boundry on a Continuous Form.

I can do this by hiding the form instead of closing, and changing lbxSelect.RowSource from the main form and unhiding. I already have many hidden forms, and this seems to slow the computer when switching between applications.
Sep 22 '10 #9
ChipR
1,287 Expert 1GB
Why not hide/close the form on exit of the textbox that caused it to open?
Sep 22 '10 #10
OldBirdman
675 512MB
That works well on the LostFocus event, but if the next control the user wants is 'under' the fSelect but not in tab order, then they must click in some other area of the main form to close fSelect. I might as well put a Close Button on fSelect and be direct about it.
Sep 22 '10 #11
ChipR
1,287 Expert 1GB
My combo boxes extend over subsequent records in continuous form view. Are you using Access 2007?
Sep 22 '10 #12
OldBirdman
675 512MB
I use Access 2003. I tried 2007 and didn't like. This is a listbox, not combobox, so not 'dropdown', which has different rules. I didn't use combobox as I didn't want entry in the text portion.
I had originally thought to use cascading comboboxes (2 levels) but this doesn't work on continuous forms for the same reasons that unbound controls (i.e. CheckBoxes) don't work. The value of combo1 of the current record applies to the RowSource for all combo2.
Sep 22 '10 #13
ChipR
1,287 Expert 1GB
So different records require different lists of options in the same field? Otherwise you could use a combo box on the main form, instead of a text box. You can even call combobox.DropDown on enter to display your list when they tab into the field. The user can then click an item on the list or use autocomplete.
Sep 22 '10 #14
OldBirdman
675 512MB
Yeah

Think States and Counties in the USA. Select state and the county list changes. Occasionally user might want to refer to something else, like 'All Counties' or in the case of Alaska, 'Not in a County'. Alaska calls them buroughs, but same logic.
So I need to use the field for standard as well as non-standard notations.
But this approach seems not to work well. Guess I'll just hide the form for now. Thanks for all the suggestions.
Sep 22 '10 #15
use the DoCmd.Close acForm, "formname"
in the "active" event on the main form so that after selecting your option on form fselct when the next form opens insert the command into that forms "active" event.
so eg. form1 make aselection and call form2, when form2 opens its "active" event closes form1.
Sep 23 '10 #16
FishVal
2,653 Expert 2GB
Form couldn't be closed while handling Deactivate event, but it could be closed while handling Timer event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Deactivate()
  2.     Me.TimerInterval = 1
  3. End Sub
  4.  
  5. Private Sub Form_Timer()
  6.     DoCmd.Close acForm, Me.Name
  7. End Sub
  8.  
Sep 23 '10 #17
OldBirdman
675 512MB
Apparently this does work. Thank you. Closing an already closed form doesn't seem to cause an error, so other causes of activate not resulting from return from fSelect aren't a problem.
I say 'Apparently' because testing the Activate condition is difficult. Any attempt to use the debugging tools cause activate/deactivate to fire as the focus moves between the program forms and the debugger.
Sep 23 '10 #18

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

Similar topics

2
by: Vivek Sharma | last post by:
How can I close a form in C#? Here is the code that I am using but closes everything? private void frmSplash_Click(object sender, EventArgs e) { this.Close(); Form frmLogin = new...
1
by: dwilliamjoe | last post by:
VB.net, launch procedure, close form, the whole APP is deactivated. When I say deactivated, other applications (Wind Explorer, My computer, Ect...) come to the foreground and my app goes to the...
5
by: AP | last post by:
IS there a way to run a procedure if the users close access directly rather than closing a menu screen that I have built? There is an event that works on close for this form, but it doesnt seem to...
4
by: Mindy | last post by:
I have two questions here: (1) what is the difference of close form and close table? (2) How "Prompt" works I used close form macro in my database. I hope when a user close the form, he/she will...
5
by: jodyblau | last post by:
I'm new at this stuff, so let me know if I am approaching this incorrectly. I have a form that allows the user to select a document that is in one folder, and copy it into another folder. I...
6
by: Robert Dufour | last post by:
On my form if the user clicks the upper right hand corner to close the form I want to trap that event and do a check to see if closing is allowed, if not, I want to stop the form closing action. ...
5
by: freelancex | last post by:
Hi, Im new to this forum, and new to scripting in general. Im an ICT Technician for a high school and i am designing a Form in visual basic 2005. The intended purpose of the Form, is to prevent...
3
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The...
22
AccessIdiot
by: AccessIdiot | last post by:
Hello all, I have a form (frm_Entrainment) with a button that opens a 2nd form (frm_Specimen_Entrainment). The 2nd form shares an ID field with the first form (Entrainment_ID - its like opening...
2
by: Hulas | last post by:
Guys, I have two questions. (a) How do I add two fields of the same table to a single combo box. For example if I have two fields ID1 and ID2 in a table called Identification, than how should I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...

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.