如何使用“Memo”比较字段 vba中的数据类型?

发布于 2024-07-16 14:34:38 字数 111 浏览 2 评论 0原文

MS Access 数据库不允许在 SQL 查询中将字段与“memo”数据类型进行比较。 有没有办法在VBA中做到这一点?

如果备忘录的大小> 255 个字符,则简单比较不起作用

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情话难免假 2024-07-23 14:34:38

使用记录集时,您可以对它们进行比较。

表:表1(int, memo, memo)

id memo1 memo2 
  1AB 
  2 直流 
  

脚本:

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

和输出:

False
True

这就是你的意思吗?

更新:对于长度为 4000 个字符的字段,它对我来说工作得很好,刚刚测试过,长度函数也工作得很好(来自 access 2003 的 vba)

问候,彼得

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

花心好男孩 2024-07-23 14:34:38

您可能有一些特定的想法,但这个简单的情况运行正常,没有错误:

    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
    ;

我知道这会截断为 255 个字符。 这是你的问题吗?
- 编辑:我已经用超过 255 个字符的值对其进行了测试,并且它没有被截断。

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.

混浊又暗下来 2024-07-23 14:34:38

我想最好的方法是将两个备注字段保存到两个文件中,然后与文件进行比较。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文