我有一张桌子......
A1 B1
A2 B2
A3 B3
A4 B4
A5 B5
。
。
。
它随机打印出来......
BLANK BLANK
BLANK BLANK
BLANK BLANK
BLANK BLANK
A4 B4
A5 B5
。
。
。
空白是我能看到的实际上是空白的。我在记录中找不到任何字符。代码如下。它打印相同数量的记录。我正在使用表单,并在表名中调用表。
Option Compare Database
Sub Concatenate(Table As String)
' Set the database
'Dim dbsCyme_Model_Update As DAO.Database
'Dim rst As DAO.Recordset
Set dbsCyme_Model_Update = CurrentDb
Dim Field As String
'Count records and fields
RecordCount = CurrentDb.TableDefs(Table).RecordCount
fieldCount = CurrentDb.TableDefs(Table).Fields.Count
Debug.Print "00000"; RecordCount; fieldCount;
RecordCounter = 0
ReDim fieldArray(0) As String
ReDim recordArray(0) As String
ReDim fieldArray(fieldCount - 1) As String
ReDim recordArray(RecordCount - 1) As String
Set rst = dbsCyme_Model_Update.OpenRecordset(Table)
rst.MoveFirst
Do Until rst.EOF
'Field data
fieldCounter = 1
While fieldCounter < fieldCount
'Set Recordset
Field = "Field" & fieldCounter
'rstGENERAL
fieldString = rst.Fields(Field)
fieldArray(fieldCounter - 1) = fieldString
fieldCounter = fieldCounter + 1
Wend
printCounter = 0
For Each element In fieldArray
If Not fieldArray(printCounter) = "N/A" Then
holder = recordArray(RecordCounter)
If fieldArray(printCounter + 1) = "N/A" Then
recordArray(RecordCounter) = holder + fieldArray(printCounter)
Else
recordArray(RecordCounter) = holder + fieldArray(printCounter) + ","
End If
printCounter = printCounter + 1
End If
Next element
RecordCounter = RecordCounter + 1
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Dim temp As String
'Print to the CymeImportFile
Dim bob As String
bob = 0
Set rst = dbsCyme_Model_Update.OpenRecordset("CymeImportFile")
'rst.MoveFirst
RecordCounter = 0
If rst.BOF Then
rst.AddNew
rst.Update
rst.MovePrevious
Else
rst.MoveLast
rst.MoveNext
rst.AddNew
rst.Update
rst.MovePrevious
End If
For Each element In recordArray
rst.Edit
temp = recordArray(RecordCounter)
rst!Field1 = temp
rst.Update
rst.MoveNext
If rst.EOF Then
rst.AddNew
rst.Update
rst.MovePrevious
End If
RecordCounter = RecordCounter + 1
Next element
rst.Close
Set rst = Nothing
ReDim fieldArray(0) As String
ReDim recordArray(0) As String
End Sub
答案 0 :(得分:0)
我明白了。所有这些不同的添加和更新混淆了一切我将其简化为此。
新代码:
'Print to the CymeImportFile
Dim bob As String
bob = 0
Set rst = dbsCyme_Model_Update.OpenRecordset("CymeImportFile")
RecordCounter = 0
rst.MoveLast
rst.AddNew
For Each element In recordArray
'rst.Edit
rst.AddNew
temp = recordArray(RecordCounter)
rst!Field1 = temp
rst.Update
RecordCounter = RecordCounter + 1
Next element
rst.Close
Set rst = Nothing
ReDim fieldArray(0) As String
ReDim recordArray(0) As String
Debug.Print Table
End Sub