|
在做一个基于OFFICE的SAP报告时
遇到奇怪的问题: 不能直接将自己创建的RECORDSET赋值给DICTIONARY
但能过中间变量又可以赋值成功
Dim J As Integer, U As Integer, LIKP, MKPF
Dim I As Integer, LIPS, HD, str As String
Dim stime, SDate As String, EDate As String
Dim SD As Date, ED As Date, str1 As String, str2 As String
Set VBELN = CreateObject("Scripting.Dictionary")
Set MKPF = CreateObject("Scripting.Dictionary")
'创建RECORDSET
Dim rs As New Recordset
rs.CursorLocation = adUseClient
rs.Fields.Append "DNo", adVarChar, 255
rs.Fields.Append "DateTimeX", adVarChar, 255
rs.Fields.Append "TCode", adVarChar, 255
rs.Fields.Append "DOc", adVarChar, 255
'----------------
'-给RECORDSET增加记录---------------
U = (TData.RowCount)
If U > 0 Then
rs.Open
For J = 1 To U
HD = Split(TData(J, "wa"), "|")
rs.AddNew
rs("DNo") = HD(3)
rs("DateTimeX") = HD(1) & HD(2)
rs("TCode") = HD(4)
rs("Doc") = HD(0)
rs.Update
Next J
End If
'=======对RECORDSET排序
If rs.RecordCount > 0 Then
rs.Sort = "Dno asc,DateTimeX asc"
rs.MoveFirst
Do Until rs.EOF
'============问题在此处,要先将RECORDSET转给str1/2,
'然后再增加到字典; 如果直接RECORDSET的增加到字典会不成功
str1 = rs("Dno")
str2 = rs("TCode")
If Trim$(str2) = "VL09" And MKPF.exists(str1) = True Then
MKPF.Remove str1
ElseIf MKPF.exists(str1) = False Then
MKPF.Add str1, str1
End If
rs.MoveNext
Loop
LIKP = MKPF.keys
rs.Close
Set rs = Nothing
End If |
|