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.