访问:转到下一条记录创建空记录

Access: Go to next record creates empty record

我有两个循环浏览记录的按钮(在本例中为员工)。

第一个按钮是上一条记录,它将浏览所有员工,直到第一个员工。到达第一位员工后,该按钮将不会执行任何操作。

但是,对于*next record *按钮,由于某些原因,在转到最后一个可见的雇员后,再次按下它会转到new或**空白** 记录。

不确定如何修复错误,

非常感谢您的帮助谢谢!

Sub WinLossSplit()
Dim ws As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False

For Each ws In Worksheets
If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then
    If Application.WorksheetFunction.CountA(ws.Range("A:A")) > 0 Then
        ws.Range("A:A").TextToColumns Destination:=ws.Range("A:B"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=True, OtherChar _
        :=True, FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
    End If
    End If

Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox ("done")
End Sub

Sub hello()

Dim a, i As Long, w(), k(), n As Long
Dim dic As Object, ws As Worksheet, s As String
For Each ws In Worksheets
dic.comparemode = vbTextCompare
'With Sheets("Sheet1")
    a = ws.Range("a1:b" & ws.Range("a" & Rows.Count).End(xlUp).Row)
'End With

ReDim w(1 To UBound(a, 1), 1 To 2)
Set dic = CreateObject("scripting.dictionary")
For i = 1 To UBound(a, 1)
    If Not IsEmpty(a(i, 1)) Then
       ' If Not dic.exists(a(i, 1)) Then
        '    n = n + 1
         '   w(n, 1) = a(i, 1): w(n, 2) = a(i, 2)
          '  dic.Add a(i, 1), Array(n, 2)
        'Else
            k = dic.Item(a(i, 1))
            w(k(0), 2) = w(k(0), 2) & "," & a(i, 2)
            dic.Item(a(i, 1)) = k
        'End If
    End If
Next
On Error Resume Next
'Set ws = Sheets("FinalReport")
On Error GoTo 0
If ws Is Nothing Then
'    Set ws = Worksheets.Add: ws.Name = "FinalReport"
End If
With ws.Range("a1")
    '.Resize(, 2).Value = Array("Array", "Datetime period")
    .Resize(, 1).Value = Array("Array", "Datetime period")
    For i = 1 To n
        If Len(w(i, 2)) > 1024 Then
            s = w(i, 2)
            .Offset(i).Value = w(i, 1)
            .Offset(i, 1).Value = s
        Else
            .Offset(i).Value = w(i, 1)
            .Offset(i, 1).Value = w(i, 2)
        End If
    Next
     ' puts in separate columns rather than string with commas
    .Offset(1, 1).Resize(n).TextToColumns _
    Destination:=.Offset(1, 1), DataType:=xlDelimited, Comma:=True
End With
Set dic = Nothing: Erase a

Next ws

End Sub

这不是错误,这是设计使然。

如果您不喜欢这样,请将表单的 属性 AllowAdditions 设置为 False。