Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 59567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:01:32+00:00 2026-05-10T18:01:32+00:00

Using VBA i have a set of functions that return an ADODB.Recordset where all

  • 0

Using VBA i have a set of functions that return an ADODB.Recordset where all the columns as adVarChar. Unfortunately this means numerics get sorted as text. So 1,7,16,22 becomes 1,16,22,7

Is there any methods that can sort numerics as text columns without resorting to changing the type of the column?

Sub TestSortVarChar()    Dim strBefore, strAfter As String    Dim r As ADODB.RecordSet    Set r = New ADODB.RecordSet   r.Fields.Append 'ID', adVarChar, 100   r.Fields.Append 'Field1', adVarChar, 100   r.Open     r.AddNew   r.Fields('ID') = '1'   r.Fields('Field1') = 'A'    r.AddNew   r.Fields('ID') = '7'   r.Fields('Field1') = 'B'    r.AddNew   r.Fields('ID') = '16'   r.Fields('Field1') = 'C'    r.AddNew   r.Fields('ID') = '22'   r.Fields('Field1') = 'D'     r.MoveFirst   Do Until r.EOF     strBefore = strBefore & r.Fields('ID') & ' ' & r.Fields('Field1') & vbCrLf     r.MoveNext   Loop    r.Sort = '[ID] ASC'     r.MoveFirst   Do Until r.EOF     strAfter = strAfter & r.Fields('ID') & ' ' & r.Fields('Field1') & vbCrLf     r.MoveNext   Loop    MsgBox strBefore & vbCrLf & vbCrLf & strAfter  End Sub 

NB: I am using Project 2003 and Excel 2003 and referencing Microsoft ActiveX DataObject 2.8 Library

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:01:33+00:00Added an answer on May 10, 2026 at 6:01 pm

    Left pad with Zeros with at least as many as maximum number digits. e.g.

    0001 0010 0022 1000

    You can use Right$() to accomplish this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using VBA to some degree, using this code: Sub ExtractEmail() Dim
I have this VBA below that is designed to loop through each WS and
I have a vba function in excel 2010 that I built using help from
I'm using Excel VBA and have a worksheet_change event like so: Private Sub Worksheet_Change(ByVal
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I m trying to select rows/columns using vba. I want to pass row numbers
I have two worksheets, one which is used to filter the other. Using VBA
I have a set of VBA classes in an MS Access database. I have
I'm using VBA to create a FileOpenDialog object so that the user can select
I have some VBA code that opens a webpage, then calls a javascript function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.