Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Function to Reverse String Characters in a Query


View products that this article applies to.

Summary

Microsoft Access 2000 includes a new function, StrReverse(), that returns a string with the characters reversed from the original argument string. For example, if you were to pass the string "ABCD" to the function, the function would return the string "DCBA."

This article shows you how to create a function called ReverseString() that uses the StrReverse() function, so that you can sort records in a query with the results of the function.

↑ Back to the top


More information

NOTE: You will receive the following error message if you use the StrReverse() function directly in a query.
Undefined function 'StrReverse' in expression.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following example demonstrates how to create and use the ReverseString() function:
  1. Open the sample database Northwind.mdb.
  2. Create a module and type the following line in the Declarations section, if it isn't already there:
    Option Explicit
    					
  3. Type the following procedure:
    Function ReverseString (MyString As String)
       ReverseString = StrReverse(MyString)
    End Function
    					
  4. Create the following new query based on the Categories table:
       Query: Query1
       -------------------------------------------
       Field: CategoryName
          Show: (selected)
       Field: Expr1: ReverseString([CategoryName])
          Sort: Ascending
          Show: (not selected)
    					
  5. On the Query menu, click Run. Note that the following items are returned:
       CategoryName
       ------------
       Seafood
       Produce
       Beverages
       Grains/Cereals
       Confections
       Dairy Products
       Condiments
       Meat/Poultry
    					
The returned records are sorted in ascending order on the CategoryName field, but the field is sorted from right to left, rather than from left to right. For example, Seafood is sorted on "d," Produce on "e," Beverages on "s," and so on.

↑ Back to the top


Keywords: KB210439, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 210439
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 340