views:

709

answers:

3

The MS access database does not allow comparing fields with 'memo' datatypes in SQL query. Is there a way to do it in VBA?

Simple comparison does not work if the size of memo>255 characters

+2  A: 

When using a recordset, you can compare them.

The table : Table1(int, memo, memo)

id   memo1     memo2
1    A      B
2    D      C

The script :

Public Sub test()

Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSql As String

Set conn = CurrentProject.Connection
strSql = "select * from Table1"

rst.Open strSql, conn

rst.MoveFirst
    While Not rst.EOF
        Debug.Print rst("memo1") > rst("memo2")
    rst.MoveNext
Wend

rst.Close
conn.Close

End Sub

And the output :

False
True

Is that what you mean?

UPDATE : it works fine for me with fields with length of 4000 chars up, just tested it, also the length function works fine (vba from access 2003)

Greetings, peter

Peter
It does not work if memo size>255 characters
Varun Mahajan
just did a quick test, and with me it works fint (I've teste the '=' operator, by comparing text from wikipedia , True when identical, False when changing a point at the end of the page)The length of the field was 4264, the length operator also worked.
Peter
I'm not sure why you posted an ADO example given that it's in VBA in Access. DAO would be the obvious choice for something like this, seems to me.
David-W-Fenton
A: 

You probably have something specific in mind but this simple case works OK with no error:

    CREATE TABLE TestMemo (memo1 MEMO, memo2 MEMO)
    ;
    INSERT INTO TestMemo (memo1, memo2) VALUES ('Blah', 'Blah')
    ;

INSERT INTO TestMemo (memo1, memo2) VALUES ('123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A', '123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789A123456789Z')
;

    SELECT memo1, memo2 
      FROM TestMemo
     WHERE memo1 = memo2
    ;

I am aware that this truncates at 255 characters. Is this your problem? - Edit: I've tested it with values exceeding 255 characters and it isn't being truncated.

onedaywhen
255 characters is the problem
Varun Mahajan
My tests show that truncation does not exhibit with equals comparison. Are you perhaps doing something else to causes truncation e.g. GROUP BY or UNION maybe?
onedaywhen
A: 

I guess the best way is save two Memo fields into 2 files and then do the comparison with files.

THEn