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

时间:2017-01-20 09:30:40

标签: database database-design macros ms-access-2013

我有两个按钮循环记录(在这种情况下为员工)。

按钮1是上一个记录,它将导航所有emoloyees直到第一个emoloyee。到达第一名员工后,该按钮不会做任何事情。

但是,对于* next record *按钮,出于某种原因,在进入最后一个可见的工作后,再次按下它将转到或**空白**记录。

不确定如何修复错误,

非常感谢帮助谢谢!

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

1 个答案:

答案 0 :(得分:0)

它不是一个错误,它是设计的。

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