Create form as constant

G

Guest

Often, I need to invoke the controls of a form that always is open, sometimes
it is visible another times it is hide.

I created a function to invoke the form

Public Function frmRpt() As Form
If IsLoaded("E1_MenuRpt") Then
Set frmRpt = Forms!E1_MenuRpt
End If
End Function

It works but always I call the function frmRpt should run this function.
I think if it is possible create a constant as form it will be better and
fater

I tried to do
const xfrm as form= "E1_MenuRpt"
It doesn't work

Is is possible create a constant global for a specific form?

Thanks
jcp
 
S

Stefan Hoffmann

hi,
Often, I need to invoke the controls of a form that always is open, sometimes
it is visible another times it is hide.

I created a function to invoke the form

Public Function frmRpt() As Form
If IsLoaded("E1_MenuRpt") Then
Set frmRpt = Forms!E1_MenuRpt
End If
End Function

It works but always I call the function frmRpt should run this function.
I think if it is possible create a constant as form it will be better and
fater
Nope. You may use a property in a normal module:

Option Compare Database
Option Explicit

Private m_FormReport As Access.Form

Public Property Get frmRpt()

On Local Error Resume Next

If m_FormReport Is Nothing Then
' If Not AllForms.Item("E1_MenuRpt").IsLoaded Then
' DoCmd.OpenForm "E1_MenuRpt"
'End If
If AllForms.Item("E1_MenuRpt").IsLoaded Then
Set m_FormReport = Forms.Item("E1_MenuRpt").Form
End If
End If

Set frmRpt = m_FormReport

End Property


mfG
--> stefan <--
 
G

Guest

So, we can not declare a form as constant. I'm informed, I don't think
anymore about this.
Thanks Stefan

I'm curiosity about your example function.

If I look my function (Function frmRpt() As Form) it looks more
unsophisticated, more simple than your example (Public Property Get frmRpt())
Do you think using property get is much better? is it faster?
I know, my function is working but if yours is better for some reasons that
I don't know, I would like to use
Thanks
 
S

Stefan Hoffmann

hi,
I'm curiosity about your example function.
If I look my function (Function frmRpt() As Form) it looks more
unsophisticated, more simple than your example (Public Property Get frmRpt())
Do you think using property get is much better? is it faster?
It's faster. Better is just a point of view question.


mfG
--> stefan <--
 
G

Guest

Just to clarify.

Why I need to declare:

Private m_FormReport As Access.Form

Thanks Stefan
 
S

Stefan Hoffmann

hi,
Just to clarify.
Why I need to declare:
Private m_FormReport As Access.Form
It is a variable storing a pointer to your instance of your report form.
It is private, because our property function fills it, when necessary.
The "when necessary" part is where you gain the most speed up. But be
aware, I'm just talking about milliseconds.

Without it, we would need you function, which evalutates every time when
its called the IsLoaded() function and the forms collection for
accessing it.


mfG
--> stefan <--
 
G

Guest

Just to clarify

Considering that the E1_MenuRpt form always is open (visible or hide) I
removed if is loaded IsLoaded("E1_MenuRpt") to gain time.

Does it make sense?

Thanks
jcp

Public Function frmRpt() As Form
On Error GoTo Err_Track

Set frmRpt = Forms!E1_MenuRpt

Exit_Track:
Exit Function

Err_Track:
MsgBox Err.Number & vbLf & "Reports Menu is closed. & vbLf & "Please,
close the Alloc System and open it again", , iMsg
Resume Exit_Track

End Function
 
S

Stefan Hoffmann

JCP said:
Just to clarify

Considering that the E1_MenuRpt form always is open (visible or hide) I
removed if is loaded IsLoaded("E1_MenuRpt") to gain time.

Does it make sense?
No, not really, in this case you would just use it directly with
Forms!E1_MenuRpt or a simple global variable which is controlled by the
form itself:

Private Sub Form_Load()

Set globalFormVar = Me

End Sub


Private Sub Form_Unload()

Set globalFormVar = Nothing

End Sub

Just take my original answer and remove the single quotes:

If m_FormReport Is Nothing Then
If Not CurrentProject.AllForms.Item("E1_MenuRpt").IsLoaded Then
DoCmd.OpenForm "E1_MenuRpt"
End If
If AllForms.Item("E1_MenuRpt").IsLoaded Then
Set m_FormReport = Forms.Item("E1_MenuRpt").Form
End If
End If

When you always use the function, you will open automatically a new
instance of your from when there is none.


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top