VB6 error sort virtual recordset

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

VB6 error sort virtual recordset

Post by sal21 »

Code: Select all


 Set RSTC = CreateObject("ADODB.Recordset")
    RSTC.CursorLocation = adUseClient
    RSTC.Fields.Append "ORIG", vbString
    RSTC.Fields.Append "COD", vbString
    RSTC.Open

    With RSTC
        For C = 0 To MYDIC.Count - 1
            .AddNew
            RSTC("COD").Value = MYDIC.Keys()(C)
            RSTC("ORIG").Value = MYDIC.Items()(C)
        Next C
    End With
    
    RSTC.MoveFirst
    RSTC.Sort = "ORIG DESC" [b]<<<<< error[/b]

note:
COD is a string valkue, ORIG is a integer value
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB6 error sort virtual recordset

Post by HansV »

Don't use vbString. In ADODB, this corresponds to a string terminated by Chr(0).
Instead, use adVarChar and specify the maximum length. For example, if ORIG and COD will be at most 30 characters:

Code: Select all

    RSTC.Fields.Append "ORIG", adVarChar, 30
    RSTC.Fields.Append "COD", adVarChar, 30
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: VB6 error sort virtual recordset

Post by sal21 »

HansV wrote:
21 Feb 2021, 19:46
Don't use vbString. In ADODB, this corresponds to a string terminated by Chr(0).
Instead, use adVarChar and specify the maximum length. For example, if ORIG and COD will be at most 30 characters:

Code: Select all

    RSTC.Fields.Append "ORIG", adVarChar, 30
    RSTC.Fields.Append "COD", adVarChar, 30
tks.
i cannot test now...

but
RSTC.CursorLocation = adUseClient

is required? or not?

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB6 error sort virtual recordset

Post by HansV »

It works without the line

Code: Select all

    RSTC.CursorLocation = adUseClient
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: VB6 error sort virtual recordset

Post by sal21 »

HansV wrote:
21 Feb 2021, 19:46
Don't use vbString. In ADODB, this corresponds to a string terminated by Chr(0).
Instead, use adVarChar and specify the maximum length. For example, if ORIG and COD will be at most 30 characters:

Code: Select all

    RSTC.Fields.Append "ORIG", adVarChar, 30
    RSTC.Fields.Append "COD", adVarChar, 30
work perfect!