Setting a Field's Control Source as a Variable (1 Viewer)

JustinS

Member
Local time
Today, 11:06
Joined
Apr 11, 2020
Messages
58
See attached picture. I have to set up a bunch of reports which will have some varying data fields. I will be using filter forms that allow the user to select what they want to view in the report. Once the desired information is selected the report is filtered via a where clause.

My question is whether there is a way to set the control source for the fields that I want to filter on up as variables? I didn't see anything in google on this subject. Thanks in advance for any help you guys can provide me with.

Variable.PNG
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:06
Joined
Oct 29, 2018
Messages
21,485
Hi. You could try concatenation. For example:

strWhere = strWhere & " [" & FieldNameVariable & "] >=" & Me.txtValueMin & " AND "
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:06
Joined
Aug 30, 2003
Messages
36,127
If I understand correctly, you want to set the control source of a textbox to a different field dynamically? You might look at dynamic crosstab reports, where the fields vary. A line of code might look like:

Me.TextboxName.ControlSource = strName

Letting the user select the fields can be messy, since you may have issues with textbox sizes being inappropriate to the data selected.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:06
Joined
Oct 29, 2018
Messages
21,485
If I understand correctly, you want to set the control source of a textbox to a different field dynamically? You might look at dynamic crosstab reports, where the fields vary. A line of code might look like:

Me.TextboxName.ControlSource = strName

Letting the user select the fields can be messy, since you may have issues with textbox sizes being inappropriate to the data selected.
Oh, oops, sorry if I misunderstood the question. Cheers!
 

JustinS

Member
Local time
Today, 11:06
Joined
Apr 11, 2020
Messages
58
Actually @theDBguy was correct on what I was looking for. I was trying to make the field to be filtered on in the report variable. The suggestion worked.

Thanks.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:06
Joined
Aug 30, 2003
Messages
36,127
Not my first misinterpretation, not likely my last. ;)

I guess you mentioning control sources and this:

allow the user to select what they want to view in the report

Which I thought meant they were choosing which fields they wanted to see on the report, not what they were filtering on. Glad dbGuy nailed it for you.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:06
Joined
Oct 29, 2018
Messages
21,485
Actually @theDBguy was correct on what I was looking for. I was trying to make the field to be filtered on in the report variable. The suggestion worked.

Thanks.
Hi. Glad to hear you got it to work. Good luck with your project.
 

Users who are viewing this thread

Top Bottom