【问题标题】:Access: Go to next record creates empty record访问:转到下一条记录创建空记录
【发布时间】:2017-01-20 09:30:39
【问题描述】:

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

按钮一个是 Previous Record,它将在所有员工中导航,直到第一个员工。到达第一个员工后,按钮不会做任何事情。

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

不知道如何修复这个错误,

非常感谢您的帮助,谢谢!

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,没有 VBA 有没有办法做到这一点?已在 Access 中使用的宏表达式生成器(编码块)上的 I.E?
    • 我猜是这样,但不能说。我不做宏。
    • 谢谢!刚刚将宏转换为 vba 并添加了您的代码行 - 它可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 2017-10-31
    • 2016-02-10
    • 1970-01-01
    相关资源
    最近更新 更多