UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Dynamically Referencing Textbox Names On A Report, Access 2016    
 
   
GamerX
post Jul 10 2018, 09:25 AM
Post#1



Posts: 12
Joined: 10-June 18



Hi

I need to dynamicaly change the name of some textboxes to retrieve the values contained within them.

Dim OtherVIRPostion as string
Dim Total as long

OtherVIRPosition = "R_" & IIf(rs_2![WhichTotalToUse] = "Total", "Tot", "Exist") & "VIRRbt_JanToDec_WFor_" & Right(Trim(rs_3![Spend_Type]), 1)
Total = [Reports]![rptReport]![OtherVIRPosition]

I get an error message "Access can't find the field OtherVIRPosition in the report"

Variations like

Total = [Reports]![rptReport]![ & OtherVIRPosition & ]
or
Total = "[Reports]![rptReport]![" & OtherVIRPosition & "]"
don't work either!

If however I stick the correct name in like so:

Total = [Reports]![rptReport]![R_ExistVIRRbt_JanToDec_WFor_1]

I can retrieve the value!

It appears only the actual name is accepted not a variable representing the name?

Does anyone know of a better way to do this or how I can dynamically retrieve
the values contained in textboxes of different names on a report?
This post has been edited by GamerX: Jul 10 2018, 09:30 AM
Go to the top of the page
 
isladogs
post Jul 10 2018, 09:31 AM
Post#2



Posts: 562
Joined: 4-June 18
From: Somerset, UK


For a start your total (long integer) can't equal a string value
Modify the datatype

If you are doing this within the same report just set your total equal to the variable
Depending on where its used you may need a number 'delimiter'

Or just use a 'sensible' textbox name and use
CODE
Total=Me.textboxname

This post has been edited by isladogs: Jul 10 2018, 09:34 AM
Go to the top of the page
 
GamerX
post Jul 10 2018, 09:41 AM
Post#3



Posts: 12
Joined: 10-June 18



Thanks, but the value being returned from the text box is a number not a string hence a long should be acceptable

I am doing this in a VBA code module not a report
hence the need for the reference to the report
[Reports]![rptReport]![OtherVIRPosition]




Go to the top of the page
 
BruceM
post Jul 10 2018, 09:44 AM
Post#4


UtterAccess VIP
Posts: 7,671
Joined: 24-May 10
From: Downeast Maine


In which event procedure are you attempting this code? Why not just look at the values in the underlying recordset?

If you are going to assemble a string that is the text box name, maybe like this:

Reports!rptReport.Controls(OtherVIRPosition)

But if this code is in the report's code module, that is taking the long way around. Can you describe in a little more detail what you need to do?

Edit:
QUOTE
I am doing this in a VBA code module not a report hence the need for the reference to the report

Which VBA code module? The report's module? A form's module? A standard module?

Also, you can pass the report's name to the calling procedure, or otherwise reference the report. You can do it as you have, but it is not the only way, and may not be the best way.
Go to the top of the page
 
isladogs
post Jul 10 2018, 09:45 AM
Post#5



Posts: 562
Joined: 4-June 18
From: Somerset, UK


The long variable is fine.
OtherViRPosition is a string

Do you mean in the report code module or a standard module?
If the latter ...why?
Go to the top of the page
 
GamerX
post Jul 10 2018, 09:49 AM
Post#6



Posts: 12
Joined: 10-June 18



Thats perfect Bruce smile.gif, I was missing the Controls bit
when I put it in like so it takes the variable name

Total = Reports!rptVISReport.Controls(OtherVIRPosition)

Thank You smile.gif





Go to the top of the page
 
GamerX
post Jul 10 2018, 09:50 AM
Post#7



Posts: 12
Joined: 10-June 18



Thanks was using a standard module
Go to the top of the page
 
BruceM
post Jul 10 2018, 09:51 AM
Post#8


UtterAccess VIP
Posts: 7,671
Joined: 24-May 10
From: Downeast Maine


Glad to help, but I have to wonder whether you are making this more complicated than is necessary.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    16th October 2018 - 10:01 AM