Error accessing control when form not open

  • Thread starter Thread starter Robin9876
  • Start date Start date
R

Robin9876

On a form when trying to get a value from a field it displays Run-time
error 2450 when the form is not open.

In this case instead of displaying the error how can I get a value
from a control on a different form?
 
You can only get a value from an open form that is displaying that value.
Just refer to the control on the open form:

[Forms]![OtherForm]![Text1]

Use DLookup to get a value from an underlying table. The form does not need
to be open.
 
How can you check that the form is already open before referring to
the control on the form?

You can only get a value from an open form that is displaying that value.
Just refer to the control on the open form:

[Forms]![OtherForm]![Text1]

Use DLookup to get a value from an underlying table. The form does not need
to be open.
--
Arvin Meyer, MCP, MVPhttp://www.datastrat.comhttp://www.mvps.org/accesshttp://www.accessmvp.com


On a form when trying to get a value from a field it displays Run-time
error 2450 when the form is not open.
In this case instead of displaying the error how can I get a value
from a control on a different form?
 
Try:

Public Function IsLoaded(strName As String) As Boolean
IsLoaded = (SysCmd(acSysCmdGetObjectState, acForm, strName) <> 0)
End Function

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


Robin9876 said:
How can you check that the form is already open before referring to
the control on the form?

You can only get a value from an open form that is displaying that value.
Just refer to the control on the open form:

[Forms]![OtherForm]![Text1]

Use DLookup to get a value from an underlying table. The form does not
need
to be open.
--
Arvin Meyer, MCP,
MVPhttp://www.datastrat.comhttp://www.mvps.org/accesshttp://www.accessmvp.com


On a form when trying to get a value from a field it displays Run-time
error 2450 when the form is not open.
In this case instead of displaying the error how can I get a value
from a control on a different form?
 
Thanks, I have since found that there is an inbuilt IsLoaded function
which I used and is working.

Try:

Public Function IsLoaded(strName As String) As Boolean
IsLoaded = (SysCmd(acSysCmdGetObjectState, acForm, strName) <> 0)
End Function

--
Arvin Meyer, MCP, MVPhttp://www.datastrat.comhttp://www.mvps.org/accesshttp://www.accessmvp.com


How can you check that the form is already open before referring to
the control on the form?
You can only get a value from an open form that is displaying that value.
Just refer to the control on the open form:
[Forms]![OtherForm]![Text1]
Use DLookup to get a value from an underlying table. The form does not
need
to be open.
--
Arvin Meyer, MCP,
MVPhttp://www.datastrat.comhttp://www.mvps.org/accesshttp://www.accessmv...

On a form when trying to get a value from a field it displays Run-time
error 2450 when the form is not open.
In this case instead of displaying the error how can I get a value
from a control on a different form?
 
Back
Top