Set Control source at runtime

S

SAC

Access 2003

I'd like the user to be able to choose whether to sort a report by one of
two criteria. I have a form with a dropdown box where they make the choice.

Depending on the choice, I'd like to set the caption of the first column of
the report to the choice and likewise set the control source of the first
column's textbox to the appropriate control source.

In the report_open event I am setting:

the recordsource for the report,
the Me.Grouplevel(0).Controlsource
and the label for the columns.

These work OK.

The record source is:

Me.RecordSource = "SELECT tblOrganization.NAME as OrgName,
tblOrganization.ADDRESS, tblOrganization.ZIPCODE FROM tblOrganization ORDER
BY tblOrganization.ZIPCODE;"

In setting the control source for the textboxes, I've tried

Me.txtNAME.ControlSource = [OrgName] but this does not work.

I get the error "Microsoft Office Access can't find the field '|' referred
to in your expression." Runtime error 2465.

What do I need to change?

Thanks for your help.
 
K

kc-mass

Assuming that OrgName is in the same table try:
Me.txtNAME.ControlSource = "OrgName"

Regards

Kevin
 
S

SAC

Excellent!!

Do you happen to know why the intellisense dos not show controlsource for an
option to Me.txtName. ??

Thanks for your help.

I really appreciate it.

kc-mass said:
Assuming that OrgName is in the same table try:
Me.txtNAME.ControlSource = "OrgName"

Regards

Kevin


SAC said:
Access 2003

I'd like the user to be able to choose whether to sort a report by one of
two criteria. I have a form with a dropdown box where they make the
choice.

Depending on the choice, I'd like to set the caption of the first column
of the report to the choice and likewise set the control source of the
first column's textbox to the appropriate control source.

In the report_open event I am setting:

the recordsource for the report,
the Me.Grouplevel(0).Controlsource
and the label for the columns.

These work OK.

The record source is:

Me.RecordSource = "SELECT tblOrganization.NAME as OrgName,
tblOrganization.ADDRESS, tblOrganization.ZIPCODE FROM tblOrganization
ORDER BY tblOrganization.ZIPCODE;"

In setting the control source for the textboxes, I've tried

Me.txtNAME.ControlSource = [OrgName] but this does not work.

I get the error "Microsoft Office Access can't find the field '|'
referred to in your expression." Runtime error 2465.

What do I need to change?

Thanks for your help.
 

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