Codes for Screen active fprm

  • Thread starter Thread starter Nandini
  • Start date Start date
N

Nandini

I created autokeys macro to open "MyHelpForm" through F1 key or shortcut
menu. For this I have created a table having 3 fields 'FormName' , 'CtrlName'
and 'HelpText'. In the standard module I wrote following code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record having
both the fields (FormName and CtrlName). But it dosent show the records
having only one field (FormName). I used Access 2003. Anybody can help me
anyway? I dont have much more knowledge
about visual basic codes.
Early response would be appreciated.
With best regards,
 
strWhere = "FormName= '" & frmCurrentForm.[Name] & "'"
If Len(strCurrentControl.[Name] & vbNullString) > 0 Then
strWhere = strWhere & " AND CtrlName = '" & ctlCurrentControl.[Name] &
"'"
End If
 
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Won't the second comparison (OR FormName... ) override the first one so that
the CtrlName will never matter?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


John Spencer (MVP) said:
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I created autokeys macro to open "MyHelpForm" through F1 key or shortcut
menu. For this I have created a table having 3 fields 'FormName' ,
'CtrlName' and 'HelpText'. In the standard module I wrote following code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show the
records having only one field (FormName). I used Access 2003. Anybody can
help me anyway? I dont have much more knowledge about visual basic codes.
Early response would be appreciated.
With best regards,
 
Thanks for your kind help. But after writing the code as suggested by you
dosent open the record having only the FormName.
With regards
--
nandini


Douglas J. Steele said:
Won't the second comparison (OR FormName... ) override the first one so that
the CtrlName will never matter?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


John Spencer (MVP) said:
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I created autokeys macro to open "MyHelpForm" through F1 key or shortcut
menu. For this I have created a table having 3 fields 'FormName' ,
'CtrlName' and 'HelpText'. In the standard module I wrote following code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show the
records having only one field (FormName). I used Access 2003. Anybody can
help me anyway? I dont have much more knowledge about visual basic codes.
Early response would be appreciated.
With best regards,
 
I may have misinterpretted what you're trying to do.

I thought you wanted it to open with all information about the form if no
control was active, and information about only the control if one was
active.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Nandini said:
Thanks for your kind help. But after writing the code as suggested by you
dosent open the record having only the FormName.
With regards
--
nandini


Douglas J. Steele said:
Won't the second comparison (OR FormName... ) override the first one so
that
the CtrlName will never matter?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


John Spencer (MVP) said:
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Nandini wrote:
I created autokeys macro to open "MyHelpForm" through F1 key or
shortcut
menu. For this I have created a table having 3 fields 'FormName' ,
'CtrlName' and 'HelpText'. In the standard module I wrote following
code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show the
records having only one field (FormName). I used Access 2003. Anybody
can
help me anyway? I dont have much more knowledge about visual basic
codes.
Early response would be appreciated.
With best regards,
 
Yes, I want to open with all information about the form if no
control was active, and information about only the control if one was
active. But that code opens only with the information about the control is
active.
With regards,

--
nandini


Douglas J. Steele said:
I may have misinterpretted what you're trying to do.

I thought you wanted it to open with all information about the form if no
control was active, and information about only the control if one was
active.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Nandini said:
Thanks for your kind help. But after writing the code as suggested by you
dosent open the record having only the FormName.
With regards
--
nandini


Douglas J. Steele said:
Won't the second comparison (OR FormName... ) override the first one so
that
the CtrlName will never matter?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Nandini wrote:
I created autokeys macro to open "MyHelpForm" through F1 key or
shortcut
menu. For this I have created a table having 3 fields 'FormName' ,
'CtrlName' and 'HelpText'. In the standard module I wrote following
code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show the
records having only one field (FormName). I used Access 2003. Anybody
can
help me anyway? I dont have much more knowledge about visual basic
codes.
Early response would be appreciated.
With best regards,
 
Note that I accidentally added a period in the last part.

That should have read
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & "'"

The above should do is open all the help for formName which means the first
set of criteria to open just the help for a specific control is ignored.
Perhaps what you want is the following:

strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR (FormName= '" & frmCurrentForm.[Name] & "' AND CtrlName is Null"

That should open the help for the form (general help on the form) and the help
for the specific control. Of course I assume that general help on the form
does not have any value in ctrlName.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I created autokeys macro to open "MyHelpForm" through F1 key or
shortcut menu. For this I have created a table having 3 fields
'FormName' , 'CtrlName' and 'HelpText'. In the standard module I wrote
following code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show the
records having only one field (FormName). I used Access 2003. Anybody
can help me anyway? I dont have much more knowledge about visual basic
codes.
Early response would be appreciated.
With best regards,
 
Did you mistakenly put the OpenForm statement inside the If statement?

It should be after the End If, not before it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Nandini said:
Yes, I want to open with all information about the form if no
control was active, and information about only the control if one was
active. But that code opens only with the information about the control is
active.
With regards,

--
nandini


Douglas J. Steele said:
I may have misinterpretted what you're trying to do.

I thought you wanted it to open with all information about the form if no
control was active, and information about only the control if one was
active.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Nandini said:
Thanks for your kind help. But after writing the code as suggested by
you
dosent open the record having only the FormName.
With regards
--
nandini


:

Won't the second comparison (OR FormName... ) override the first one
so
that
the CtrlName will never matter?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Nandini wrote:
I created autokeys macro to open "MyHelpForm" through F1 key or
shortcut
menu. For this I have created a table having 3 fields 'FormName' ,
'CtrlName' and 'HelpText'. In the standard module I wrote following
code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show
the
records having only one field (FormName). I used Access 2003.
Anybody
can
help me anyway? I dont have much more knowledge about visual basic
codes.
Early response would be appreciated.
With best regards,
 
Yes I put the OpenForm statement after the End If.
With regards
--
nandini


Douglas J. Steele said:
Did you mistakenly put the OpenForm statement inside the If statement?

It should be after the End If, not before it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Nandini said:
Yes, I want to open with all information about the form if no
control was active, and information about only the control if one was
active. But that code opens only with the information about the control is
active.
With regards,

--
nandini


Douglas J. Steele said:
I may have misinterpretted what you're trying to do.

I thought you wanted it to open with all information about the form if no
control was active, and information about only the control if one was
active.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Thanks for your kind help. But after writing the code as suggested by
you
dosent open the record having only the FormName.
With regards
--
nandini


:

Won't the second comparison (OR FormName... ) override the first one
so
that
the CtrlName will never matter?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Nandini wrote:
I created autokeys macro to open "MyHelpForm" through F1 key or
shortcut
menu. For this I have created a table having 3 fields 'FormName' ,
'CtrlName' and 'HelpText'. In the standard module I wrote following
code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show
the
records having only one field (FormName). I used Access 2003.
Anybody
can
help me anyway? I dont have much more knowledge about visual basic
codes.
Early response would be appreciated.
With best regards,
 
Actually, I see that the Help file says "If no control has the focus when
you use the ActiveControl property, or if all of the active form's controls
are hidden or disabled, an error occurs.", so it would seem that you've
always got an ActiveControl or Set ctlCurrentControl = Screen.ActiveControl
would raise an error.

That means John's suggestion of

strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR (FormName= '" & frmCurrentForm.[Name] & "' AND CtrlName is Null"

would be what you need.
 
strWhere = "FormName= '" & frmCurrentForm.[Name] & "'"
If Len(strCurrentControl.[Name] & vbNullString) > 0 Then
strWhere = strWhere & " AND CtrlName = '" &
ctlCurrentControl.[Name] &
"'"
End If

I find it disturbing to see references to a control not using Me.
I'd think that everyone should be using Me!ctlCurrentControl instead
of just ctlCurrentControl. The latter may *work*, but I'd say it's a
terrible idea, since it's not clear whether it's a variable or a
control or a property or method.
 
Thanks for your kind help. But that opens the help for the form (general help
on the form) only and dose not open the help for the specific control.
With regards.
--
nandini


Douglas J. Steele said:
Actually, I see that the Help file says "If no control has the focus when
you use the ActiveControl property, or if all of the active form's controls
are hidden or disabled, an error occurs.", so it would seem that you've
always got an ActiveControl or Set ctlCurrentControl = Screen.ActiveControl
would raise an error.

That means John's suggestion of

strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR (FormName= '" & frmCurrentForm.[Name] & "' AND CtrlName is Null"

would be what you need.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Nandini said:
Yes I put the OpenForm statement after the End If.
 
Thanks for your kind help. But that opens only the help for the form (general
help on the form) and dose not open the help for the specific control. Please
help me. What should I do.
With regards,
--
nandini


John Spencer (MVP) said:
Note that I accidentally added a period in the last part.

That should have read
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & "'"

The above should do is open all the help for formName which means the first
set of criteria to open just the help for a specific control is ignored.
Perhaps what you want is the following:

strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR (FormName= '" & frmCurrentForm.[Name] & "' AND CtrlName is Null"

That should open the help for the form (general help on the form) and the help
for the specific control. Of course I assume that general help on the form
does not have any value in ctrlName.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
strWhere = "(FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "')" & _
" OR FormName= '" & frmCurrentForm.[Name] & ".'"


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
I created autokeys macro to open "MyHelpForm" through F1 key or
shortcut menu. For this I have created a table having 3 fields
'FormName' , 'CtrlName' and 'HelpText'. In the standard module I wrote
following code:

Public Function OpenMyHelpForm()
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
Dim strWhere as String
strWhere = "FormName= '" & frmCurrentForm.[Name] & _
"' AND CtrlName = '" & ctlCurrentControl.[Name] & "'"
DoCmd.OpenForm "MyHelpForm", , , strWhere
End Function

MyHelpForm is opened after pressing F1 and it shows only the record
having both the fields (FormName and CtrlName). But it dosent show the
records having only one field (FormName). I used Access 2003. Anybody
can help me anyway? I dont have much more knowledge about visual basic
codes.
Early response would be appreciated.
With best regards,
 
David W. Fenton said:
strWhere = "FormName= '" & frmCurrentForm.[Name] & "'"
If Len(strCurrentControl.[Name] & vbNullString) > 0 Then
strWhere = strWhere & " AND CtrlName = '" &
ctlCurrentControl.[Name] &
"'"
End If

I find it disturbing to see references to a control not using Me.
I'd think that everyone should be using Me!ctlCurrentControl instead
of just ctlCurrentControl. The latter may *work*, but I'd say it's a
terrible idea, since it's not clear whether it's a variable or a
control or a property or method.

Perhaps you should have read the original question, as opposed to simply
commenting on my response.

ctlCurrentControl is a variable:

Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
 
Back
Top