0

我正在使用 Access 运行 VBA 代码。我有一个通过记录集查询“rstQueryTrainings”运行的数组。在此查询中,每个 ID 有多个行。我希望这个数组能够识别一行是否包含 rstQueryTrainings 中的第一个唯一 ID,如果是,则创建一个字符串。如果它不是记录集中的第一个唯一 ID,则创建一个不同的字符串。需要注意的是,这些字符串构成了电子邮件的正文。我的代码使用 Recordset Findfirst 属性,如果有匹配项,则为该记录添加书签。如果记录已添加书签,则运行字符串。如果它没有加入书签,则运行不同的字符串。我收到以下错误:

错误 3077:表达式中的语法错误(逗号)

我不确定是否会弹出此错误,因为我在数组中使用 FindFirst。

requiredTrain = ""
        If tArraySize <> -1 Then
            ID = ""
            For eachTraining = 0 To tArraySize
                ID = PersonnelCompList(eachTraining)
                Debug.Print ID
                IDstring = "PersonnelCompList = " & ID
                Debug.Print IDstring
                rstQueryTrainings.FindFirst IDstring
                If Not rstQueryTrainings.NoMatch Then
                    rstQueryTrainings.Bookmark = varFirstMark
                End If  
                If IsEmpty(rstQueryTrainings.Bookmark) Then
                    requiredTrain = requiredTrain + "<LI>" & "<b>Course</b>: " & ", " & trainingList(eachTraining) & ", <b>Number</b>: " & courseNumList(eachTraining) & ", <b>Link</b>: " & courseNumList(eachTraining) & " | </b>" & statusList(eachTraining) & "</b>" & " (" & daysRemaining(eachTraining) & " days remaining)" & "</LI>"
                Else
                    requiredTrain = requiredTrain + "<b>Personnel Due</b>: " & PersonnelCompList(eachTraining) & "<LI>" & "<b>Course</b>: " & ", " & trainingList(eachTraining) & ", <b>Number</b>: " & courseNumList(eachTraining) & ", <b>Link</b>: " & courseNumList(eachTraining) & " | </b>" & statusList(eachTraining) & "</b>" & " (" & daysRemaining(eachTraining) & " days remaining)" & "</LI>"
                End If
                Debug.Print requiredTrain
            Next eachTraining
        End If
4

1 回答 1

0

我不确定书签的用途。这应该这样做:

requiredTrain = ""
For eachTraining = 0 To tArraySize
    ID = PersonnelCompList(eachTraining)
    Debug.Print ID
    IDstring = "PersonnelCompList = " & ID
    Debug.Print IDstring
    rstQueryTrainings.FindFirst IDstring
    If rstQueryTrainings.NoMatch Then
        requiredTrain = requiredTrain + "<LI>" & "<b>Course</b>: " & ", " & trainingList(eachTraining) & ", <b>Number</b>: " & courseNumList(eachTraining) & ", <b>Link</b>: " & courseNumList(eachTraining) & " | </b>" & statusList(eachTraining) & "</b>" & " (" & daysRemaining(eachTraining) & " days remaining)" & "</LI>"
    Else
        requiredTrain = requiredTrain + "<b>Personnel Due</b>: " & PersonnelCompList(eachTraining) & "<LI>" & "<b>Course</b>: " & ", " & trainingList(eachTraining) & ", <b>Number</b>: " & courseNumList(eachTraining) & ", <b>Link</b>: " & courseNumList(eachTraining) & " | </b>" & statusList(eachTraining) & "</b>" & " (" & daysRemaining(eachTraining) & " days remaining)" & "</LI>"
    End If
    Debug.Print requiredTrain
Next eachTraining
于 2020-03-11T07:58:03.193 回答