Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2006

Tip: Looking for answers? Try searching our database.

Trim statement with an array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joanne - 26 Sep 2006 22:48 GMT
Hello,
I have the following code which will look at the values typed into a text
box, determine whether or not there is more then one name, then create an
array if there is more than one name and put the results into a select
statement.  It seemed to be working fine until I added the "Trim" line.  Am I
not allowed to trim an array? The user may enter one name like "Harold Bloom"
or he may enter something like "Harold Bloom, Philip Roth".  I need to remove
that space between the comma and "Philip Roth" so I used the Trim statement
but it keeps telling me the subscript is out of range.  Thanks very much for
your help in advance.

If Len(Trim(vstrSearch)) > 0 Then
          If vstrResult > 0 Then
             straryElement = Split(vstrSearch, ",")
             intFinalNumber = UBound(straryElement)
           End If

For intCounter = 0 To intFinalNumber
           straryElement(intCounter) = Trim(straryElement(intCounter))
             If intFinalNumber > 0 Then
               If intCounter = 0 Then
                 strSQLSearch = "'" & straryElement(intCounter)
               Else
                 strSQLSearch = strSQLSearch & "' OR " & vTextHeading &
"='" & straryElement(intCounter) & "'"
               End If
           End If
       Next intCounter
               
  End If
Brendan Reynolds - 27 Sep 2006 10:25 GMT
Your array gets dimensioned only if the value of vstrResult is greater than
0, but subsequent code attempts to loop the array regardless of whether it
has been dimensioned or not ...

   If Len(Trim(vstrSearch)) > 0 Then

       'Array dimensioned only if value of vstrResult greater than 0

       If vstrResult > 0 Then
           straryElement = Split(vstrSearch, ",") 'array dimensioned only
if value of vstrResult greater than 0
           intFinalNumber = UBound(straryElement)
       End If

       'Attempt to loop array that may not have been dimensioned.

       For intCounter = 0 To intFinalNumber
           straryElement(intCounter) = Trim(straryElement(intCounter))
           If intFinalNumber > 0 Then
               If intCounter = 0 Then
                   strSqlSearch = "'" & straryElement(intCounter)
               Else
                   strSqlSearch = strSqlSearch & "' OR " & vTextHeading &
"='" & straryElement(intCounter) & "'"
               End If
           End If
       Next intCounter
  End If

Signature

Brendan Reynolds
Access MVP

> Hello,
> I have the following code which will look at the values typed into a text
[quoted text clipped - 31 lines]
>
>   End If
Joanne - 27 Sep 2006 22:10 GMT
Thank you so much for your reply.  I'm afraid, though that I don't quite
understand what I'm supposed to do to fix the problem - put all the code so
that it falls within the first IF statement?  I'm also not sure why it worked
until I added the trim statement.  Could you possibly clarify?

> Hello,
> I have the following code which will look at the values typed into a text
[quoted text clipped - 26 lines]
>                
>    End If
Brendan Reynolds - 28 Sep 2006 09:46 GMT
The question you need to ask yourself is, what do you want to happen if the
value of vstrResult is *not* greater than zero? That's not a question that I
can answer for you, as I have no idea what that value represents or how it
relates to the problem at hand.

Signature

Brendan Reynolds
Access MVP

> Thank you so much for your reply.  I'm afraid, though that I don't quite
> understand what I'm supposed to do to fix the problem - put all the code
[quoted text clipped - 38 lines]
>>
>>    End If
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.