im使用UNION声明来组合两个表的记录.问题是,当我使用这个UNION时,长度超过255个字符的长字段在第255个字符中被省略. 当我使用单一 Select 时,那么根本没有问题.我发现问题出在UNION声明上.如果我使用union所有问题就得到了解决,但我不想使用UNION所有. 知道为什么会发生这种情况吗?我try 过铸造场,但没有任何效果
im使用UNION声明来组合两个表的记录.问题是,当我使用这个UNION时,长度超过255个字符的长字段在第255个字符中被省略. 当我使用单一 Select 时,那么根本没有问题.我发现问题出在UNION声明上.如果我使用union所有问题就得到了解决,但我不想使用UNION所有. 知道为什么会发生这种情况吗?我try 过铸造场,但没有任何效果
对,255个字符是限制.
如果需要,您可以使用第二个查询来查找完整的备忘录.
然而,即使您可以直接将备忘录字段填写为64 K,查询也只能检索到32 K.
更糟糕的是,如果您用(例如)Rich Text Box控件填充备忘录字段,则可以达到兆字节字段内容大小,而仍然只能检索到前32 K.
为了避免此问题,您可以使用DLookup来获取完整内容.现在,当内容小于32 K时,调用DSYS是浪费时间;因此DSYS只应在必要时使用.
以下是实现这一目标的一种旧方法:
Public Function LookupMemo( _
ByVal strSource As String, _
ByVal strFieldID As String, _
ByVal strFieldMemo As String, _
ByRef lngID As Long, _
ByRef varMemo As Variant) _
As String
' Extracts without truncation to 32768 characters the ' content of a memo field in a query.
'
' Assumes proper wrapping of table/field names containing spaces
' like "[My field name]" and a single field unique numeric key.
'
' Typical usage (SQL):
'
' SELECT
' ID,
' LookupMemo("Table1", "ID", "MemoField", [ID], [MemoField]) AS FullMemo
' FROM
' Table1;
'
' 2003-12-29. Cactus Data ApS, CPH.
' Maximum length of string from memo field when retrieved in a query.
Const clngStrLen As Long = &H8000&
Dim strExpr As String
Dim strDomain As String
Dim strCriteria As String
Dim strMemo As String
Dim lngLen As Long
On Error GoTo Exit_LookupMemo
If Not IsNull(varMemo) Then
lngLen = Len(varMemo)
If lngLen < clngStrLen Then
' The memo field is not truncated.
strMemo = varMemo
ElseIf Len(strSource) > 0 And Len(strFieldID) > 0 And Len(strFieldMemo) > 0 Then
' The memo is probably truncated by the query.
' Lookup the full memo in strSource.
strExpr = strFieldMemo
strDomain = strSource
strCriteria = strFieldID & " = " & lngID & ""
strMemo = vbNullString & DLookup(strExpr, strDomain, strCriteria)
End If
Else
' Return empty string.
End If
LookupMemo = strMemo
Exit_LookupMemo:
Exit Function
Err_LookupMemo:
' Return empty string.
Resume Exit_LookupMemo
End Function