Home > Archive > MS Access database support > April 2006 > trying to use a variable as a part of a string....why is this









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author trying to use a variable as a part of a string....why is this
sparks

2006-04-05, 9:35 am


tempname = FindSpaces(rs![column 1])
this works fine but if I try to pass a variable value to it

For i = 1 To 3 Step 2
tempname = FindSpaces(rs![column (i)])

why can't the variable i just be used in this way?
Is it because of the space in the name column 1 or is
it something else?

thanks for any pointers

Jerry

DickChristoph

2006-04-05, 11:36 am

Hi Jerry

try instead

dim strName as string

For i = 1 To 3 Step 2
strname = "Column " & trim(str(i))
tempname = FindSpaces(rs.fields(strname))
next

-Dick Christoph
"sparks" <jstalnak@swbell.net> wrote in message
news:uac732dhtmfnd9v
1o2igo72lpoq3cnsq1v@
4ax.com...
>
> tempname = FindSpaces(rs![column 1])
> this works fine but if I try to pass a variable value to it
>
> For i = 1 To 3 Step 2
> tempname = FindSpaces(rs![column (i)])
>
> why can't the variable i just be used in this way?
> Is it because of the space in the name column 1 or is
> it something else?
>
> thanks for any pointers
>
> Jerry
>



sparks

2006-04-05, 11:36 am

that did it thanks a lot.
but why do you have to rebuild the string, is it because of the space
in the name?

Jerry


On Wed, 05 Apr 2006 15:34:10 GMT, "DickChristoph"
<dchristo99@yahoo.com> wrote:

>Hi Jerry
>
>try instead
>
>dim strName as string
>
>For i = 1 To 3 Step 2
> strname = "Column " & trim(str(i))
> tempname = FindSpaces(rs.fields(strname))
>next
>
>-Dick Christoph
>"sparks" <jstalnak@swbell.net> wrote in message
> news:uac732dhtmfnd9v
1o2igo72lpoq3cnsq1v@
4ax.com...
>


DickChristoph

2006-04-05, 8:28 pm

Hi Jerry

No It is because the syntax of VBA doesn't allow a variable in this context.

Given this it would expect the field name is "column (i)" which not only
isn't what you want but has nothing to do with the value of i.


-Dick Christoph
"sparks" <jstalnak@swbell.net> wrote in message
news:ovp732drq8kk5ac
jii0bi5ot20rscuio8t@
4ax.com...[color=darkred]
> that did it thanks a lot.
> but why do you have to rebuild the string, is it because of the space
> in the name?
>
> Jerry
>
>
> On Wed, 05 Apr 2006 15:34:10 GMT, "DickChristoph"
> <dchristo99@yahoo.com> wrote:
>
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com