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
> Recordset Fieldname From Variable    
 
   
mikesd
post Dec 17 2014, 11:44 PM
Post#1



Posts: 49
Joined: 16-November 02



why is it when I call a field name, incrementing it like so
For x =1 to 10
rsLayout("layout_header" & x)
Next

It works but if I call it like so

For x =1 to 10
fieldname = "field" & x & "_data"
rsLayout(fieldname)
Next
It returns an error saying it is ordinal (not recognised), tried converting it to a string with CStr(fieldname) with no luck

Any input is appreciated
thanks
Mike
Go to the top of the page
 
dmhzx
post Dec 18 2014, 05:11 AM
Post#2



Posts: 7,033
Joined: 22-December 10
From: England


Two thoughts- untested

1) try
fieldname = "field'" & x & '"_data" (That is an apostrophe after field and another before the underscore. - You MAY be stretching the Access ability to coerce form number to string.


2) If that doesn't work, maybe wrapping all the stuff after the "=" with EVAL might help
Go to the top of the page
 
mikesd
post Dec 18 2014, 05:31 AM
Post#3



Posts: 49
Joined: 16-November 02



Thanks dmhzx,

The EVAL worked, had me beat, never used Eval, had considered the Execute command
but passed on that for the supposed security issues.

thanks again
Mike
Go to the top of the page
 
cheekybuddha
post Dec 18 2014, 06:10 AM
Post#4


UtterAccess VIP
Posts: 9,277
Joined: 6-December 03
From: Telegraph Hill


What is fieldname declared as?

It's strange that it doesn't work as you originally posted.

Having said that, the code as you've posted does nothing - you neither set nor assign the value of the field.

Do you really have fields named field1_data through field10_data - maybe time to have a look at your table design! </normalisation_police>

d
Go to the top of the page
 
dmhzx
post Dec 18 2014, 06:29 AM
Post#5



Posts: 7,033
Joined: 22-December 10
From: England


MikeSD: I've never QUITE understood Eval, but found it of some use when I was trying to sot code subs and functions.

Glad it worked for you thumbup.gif

Mike and David: - I'd assumed that this was primarily a 'techniques' question, but do support David's comments about naming of fields: But of course we don't know our 'situation':


David: Loved the Normalisation Police comment thumbup.gif
Go to the top of the page
 
cheekybuddha
post Dec 18 2014, 06:34 AM
Post#6


UtterAccess VIP
Posts: 9,277
Joined: 6-December 03
From: Telegraph Hill


I'm still curious about why it didn't work in the first place - resorting to Eval() shouldn't be necessary here.

I too thought this might be a theoretical exercise, but thought I'd bring up the design issue too! wink.gif

d
Go to the top of the page
 
mikesd
post Dec 18 2014, 05:50 PM
Post#7



Posts: 49
Joined: 16-November 02



I only posted the trim version, yes all was declared. I am using it
to retrieve field names and table headers from the database.
Long term object is to allow the user the option of defining layout
of products with varying content. ie from a datasheet.

When time allows I will strip the code, go back to basics and find out why
it needed the eval this time.

thanks to all for the input, much appreciated

Mike
Go to the top of the page
 
cheekybuddha
post Dec 30 2014, 07:21 AM
Post#8


UtterAccess VIP
Posts: 9,277
Joined: 6-December 03
From: Telegraph Hill


yw.gif

David and I are happy to help!

Good luck with your project,

d
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    14th December 2017 - 12:59 AM