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

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
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?

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
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.
 
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.
 

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