Call value from table not form

D

Dave

I am probably overlooking something stupid here but, I need to pull a value
from a table when a form is not open?

Dim InternalEmail As String
InternalEmail = Forms!frmCommitteeEmail!DMEmail

this gives an error if the form frmCommitteeEmail is not already open. I am
pretty sure that is the problem because if I add code to first open the form
it works fine.

Any help here will be appreciated.

Thanks in advance
 
R

Rick Brandt

Dave said:
I am probably overlooking something stupid here but, I need to pull a
value from a table when a form is not open?

Dim InternalEmail As String
InternalEmail = Forms!frmCommitteeEmail!DMEmail

this gives an error if the form frmCommitteeEmail is not already
open. I am pretty sure that is the problem because if I add code to
first open the form it works fine.

Any help here will be appreciated.

Thanks in advance

The DLookup() function should do what you want...

DLookup("FieldName", "TableOrQueryName", "Filter Criteria")
 
D

Dave

So I can just replace this:
InternalEmail = Forms!frmCommitteeEmail!DMEmail


with this:
InternalEmail = DLookup("DMEmail", "tblCommitteeEmail", "")

Dave
 
R

Rick Brandt

Dave said:
So I can just replace this:
InternalEmail = Forms!frmCommitteeEmail!DMEmail


with this:
InternalEmail = DLookup("DMEmail", "tblCommitteeEmail", "")

If you need no criteria then just leave that argument out...

InternalEmail = DLookup("DMEmail", "tblCommitteeEmail")
 
D

Dave

Yep I took that argument out and it still did not work.
However (as usual) it was operator error.
That particular table is a "ref" not a "tbl" - so I was calling something
that did not exist.

All is good in the world now.

Thanks much

dave
 
Top