Error accessing control when form not open

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?
 
A

Arvin Meyer [MVP]

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.
 
R

Robin9876

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?
 
A

Arvin Meyer [MVP]

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?
 
R

Robin9876

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?
 

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