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

Close form problem

jpr
I am using moduled to open forms. I run them from a menu that I have
created on the toolbar. The source of the forms are queries all with
record source to "lstpreinterview" on a form named eforms.

Public Function Openmyform()
If IsNull(Forms!eforms!lstPreInterview) Then
MsgBox "Sorry. You need to select a record!"
Exit Function

Else
'If the record has been selected, well then it can open the macro
Openemyform
If Not IsNull(Forms!eforms!lstPreInterview) Then
DoCmd.OpenForm ("Myform")
End If
End If

End Function

I would like to be able to scroll from one form to the other so that
users just select the required form and can open it. What happens, is
that when a form is opened, the active one should close or I can have
up to 20 forms opened at the same time. Is there a way I can do this
withouth having to provide the form name? And where should I place the
code?
Thanks.

Feb 13 '07 #1
2 2916
option compare database
option explicit

Function CloseAllForms()

Dim i As Integer
Dim Frm As Form

For i = 0 To (Application.CurrentProject.AllForms.Count - 1)
If IsLoaded(Application.CurrentProject.AllForms(i).Na me) Then
Set Frm = Forms(Application.CurrentProject.AllForms(i).Name)
DoCmd.Close acForm, Frm.Name
End If
Next i

End Function

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <conDesignView Then
IsLoaded = True
End If
End If

End Function

Isloaded is a useful function to open supporting forms from a major form,
for example if you have a telephone directory, you might have a table (and
form) of local towns. You can check if it is already open.

Run the CloseAllForms Function befor opening the next form you want to open

HTH

Phil
"jpr" <jp***@tin.itwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>I am using moduled to open forms. I run them from a menu that I have
created on the toolbar. The source of the forms are queries all with
record source to "lstpreinterview" on a form named eforms.

Public Function Openmyform()
If IsNull(Forms!eforms!lstPreInterview) Then
MsgBox "Sorry. You need to select a record!"
Exit Function

Else
'If the record has been selected, well then it can open the macro
Openemyform
If Not IsNull(Forms!eforms!lstPreInterview) Then
DoCmd.OpenForm ("Myform")
End If
End If

End Function

I would like to be able to scroll from one form to the other so that
users just select the required form and can open it. What happens, is
that when a form is opened, the active one should close or I can have
up to 20 forms opened at the same time. Is there a way I can do this
withouth having to provide the form name? And where should I place the
code?
Thanks.

Feb 14 '07 #2
On Feb 13, 7:36 am, "jpr" <j...@tin.itwrote:
>
I would like to be able to scroll from one form to the other so that
users just select the required form and can open it. What happens, is
that when a form is opened, the active one should close or I can have
up to 20 forms opened at the same time. Is there a way I can do this
withouth having to provide the form name? And where should I place the
code?
Thanks.

Let's see if I understand this..

You have a listbox on a form called lstPreInterview?
And the value selected in it is the name of a form you want to open?
If so, what will happen if someone selects a form that is already
open? Does it just receive focus and move to the foreground?

If this is correct I would write the following careful of line wraps..
Provide additional error trapping as you see fit.

Public Function Openmyform()
Dim frmName As String
Dim frm As Form

'If list is null or empty stop running
frmName= Nz(Forms("eforms").lstPreInterview,"")
If frmName="" then
MsgBox "Sorry. You need to select a record!"
Exit Function
End If

'See if form is already open
'Set focus if it is, open otherwise
On Error Resume Next
Set frm=Forms(frmName)
If Err=0 then
frm.SetFocus
Exit Function
End If

DoCmd.OpenForm frmName
Set frm=Nothing

End Function
I would like to be able to scroll from one form to the other so that
users just select the required form and can open it. What happens, is
that when a form is opened, the active one should close or I can have
up to 20 forms opened at the same time. Is there a way I can do this
withouth having to provide the form name? And where should I place the
code?
Thanks.
As to your last comments, I believe you can have as many forms on
screen as memory allows, although people might find it anoying having
to close a multitude. I would think that closing a form just because
you open a new one in code could be a problem. This introduces the
likelyhood of data corruption (users not finished what they are doing
in it) and events on that form preventing it from being closed -
thereby making new problems in keeping track of what's still open.
And no you can't open a form without knowing it's name.

Feb 14 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Rick Collard | last post by:
I can consistently crash Access 2002 SP2 using a /runtime switch on an mdb that has the Compact on Close property set after opening and closing a form that uses the References collection. Remove...
2
by: chanchito_cojones | last post by:
hi there, I am needing some help with a database I am putting together. The database works off of a main Form, which then has buttons on it that will open up other forms. The problem I am having...
1
by: Martin Douglas | last post by:
Hey guys, maybe someone can help me with some MDI issues I have. A co-worker asked me a very simple question, one that I blew off as trivial, and it has become a time-consuming issue. Simply...
6
by: Ashish | last post by:
It might be basics for many but I never gave attention on this before. Steps: Add 2 forms (Form1/Form2) in application. Create a object in Form1 for Form2. Form2 f2 = new Form2(); //line...
7
by: Alice | last post by:
Hi, In my program, the user can navigate to many different forms. When they go to the next form, I want the form they have left to close. However, the forms aren't closing. Can anyone tell me...
19
by: Nathan | last post by:
I know this has been asked previously, but I've run into a situation where I need to know the difference between close and dispose, and I can't get the information I need from msdn help or previous...
4
by: erick-flores | last post by:
Hello I am using an If statement to test if a field = IsNull then close that form and open another one. Here is the code: Private Sub Form_Load() If IsNull(Me.loc_fk) Then MsgBox "This...
4
by: Jason Huang | last post by:
Hi, In my C# windows form project, how do I in a formA open another formB, and close formA when formB is opened? Thanks for help. Jason
3
by: rajashekar4dotnet | last post by:
how to open one form from the other form and close the first form if there are only two forms in windows application(VB.net) i had tried this method dim f as new form2 form2.show( )...
7
by: Sin Jeong-hun | last post by:
I have a dialog form which pops up from the main window using the ShowDialog() method. this dialog has no or button, and it has quite a lot of controls on it. Now, I want to close this dialog...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.