Reference to a field on a form

S

Scott

I am trying to get a report to open with data that is from a record that is
on a form. The command button is on the form and the report is supposed to
open filtered to the id of the record on the form. It is a simple thing, but
for some reason it is not behaving as I would expect. The name of the form
is InfoData and the name of table from which the form gets the ID I need is
TblVolInfo.

The code is:

Dim stOpenReport as string
Dim stLinkCriteria as string

stOpenReport = "Volunteer Info"
stLinkCriteria = "Person_PlaceID = " & Me!Person_PlaceID

Then it goes to the SQL statement that opens the form.

The code stops at where it is trying to put the Person_PlaceID in the
variable. It says it is unable to find the referenced field. I tried a
number of variations on the reference, including
Me!TblVolInfo.Person_PlaceID, Forms!InfoData.Person_PlaceID, etc. and I get
virtually the same result.

I was able to work around it by creating a control on the form called ID
whose source is Person_PlaceID and changing the code to say:

stLinkCriteria = "Person_PlaceID = " & Me!ID

I then hide the control on the form because it is superfluous for users.

But it seems to me that the code above should work. Any suggestions?
 
R

ruralguy via AccessMonster.com

Have you tried:
stLinkCriteria = "Person_PlaceID = " & [Person_PlaceID]
 
S

Scott

That doesn't work either.

ruralguy via AccessMonster.com said:
Have you tried:
stLinkCriteria = "Person_PlaceID = " & [Person_PlaceID]
I am trying to get a report to open with data that is from a record that is
on a form. The command button is on the form and the report is supposed to
open filtered to the id of the record on the form. It is a simple thing, but
for some reason it is not behaving as I would expect. The name of the form
is InfoData and the name of table from which the form gets the ID I need is
TblVolInfo.

The code is:

Dim stOpenReport as string
Dim stLinkCriteria as string

stOpenReport = "Volunteer Info"
stLinkCriteria = "Person_PlaceID = " & Me!Person_PlaceID

Then it goes to the SQL statement that opens the form.

The code stops at where it is trying to put the Person_PlaceID in the
variable. It says it is unable to find the referenced field. I tried a
number of variations on the reference, including
Me!TblVolInfo.Person_PlaceID, Forms!InfoData.Person_PlaceID, etc. and I get
virtually the same result.

I was able to work around it by creating a control on the form called ID
whose source is Person_PlaceID and changing the code to say:

stLinkCriteria = "Person_PlaceID = " & Me!ID

I then hide the control on the form because it is superfluous for users.

But it seems to me that the code above should work. Any suggestions?
 
R

ruralguy via AccessMonster.com

What is the name of the control and what is the name of the field to which it
is bound?
That doesn't work either.
Have you tried:
stLinkCriteria = "Person_PlaceID = " & [Person_PlaceID]
[quoted text clipped - 30 lines]
 
A

AccessVandal via AccessMonster.com

Is Name AutoCorrect enabled with “Track name AutoCorrect info†and “Perform
name AutoCorrect†and are they checked?

Scott wrote:
snip...
 
S

Scott

They are checked. I'm not sure what I need to do to enable Name AutoCorrect.

The previous helper (RuralGuy) may have hit on what my problem is. The
referencing does not work if I do not have a control on the form. Once I put
the control on the form it worked as it should. I guess I thought it should
be possible to reference a field from the table or query that is the source
for the form, even if the field is not the source for a control. Am I wrong?

The name of the field I want to reference is Person_PlaceID, which is in the
table VolInfo. When I create a control (named ID) whose source is
Person_PlaceID, it works.
 
A

AccessVandal via AccessMonster.com

Are you saying that there is no control name “Person_PlaceID†on your form?
If that’s the case, it will not work. Since you have now a control name “IDâ€
use this one.

You can’t use the bang to reference the field of the table without opening
the table with a DAO or ADODB recordsets.

You can use the Dot instead of the Bang to refer to a control name in your
form, however you’ll need to create the control and save the form first
before you can use the Dot. Controls not save will not be avialable in the
intellisense.
 

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