访问VB代码不起作用

时间:2018-04-13 15:03:35

标签: vba ms-access access-vba

这是它没有编译的地方:

            DoCmd.RunSQL "UPDATE InspEvent " & _
                 "SET InspEvent.SpecsLoaded = lngRecordsAdded " & _
                 "WHERE InspEvent.EventId = [Forms]![frmInspEvent]![txtEventId];"

1 个答案:

答案 0 :(得分:0)

查看原始代码,您在代码模块中定义了TransactionType Amount TransactionCount TotalAmount TotalTrans Voids AgentCredit -$1.00 49 -$49.00 49 0 MailFee $1.25 520 $650.00 531 11 HardCardFee $5.00 232 $1,160.00 239 7 QuotaHuntFee $2.00 201 $402.00 202 1

一次更新将是:

lngRecordsAdded

修改
另一种方式是:

DoCmd.RunSQL "UPDATE InspEvent " & _
             "SET InspEvent.SpecsLoaded = " & lngRecordsAdded & _
             " WHERE InspEvent.EventId = " & [Forms]![frmInspEvent]![txtEventId]  

编辑2:
查看原始代码,您还可以使用以下代码块:

Dim qdf As DAO.QueryDef
Set qdf = CurrentDb.QueryDefs("", "PARAMETERS RecordsAdded LONG, Event_Identifier LONG; " & _
    "UPDATE InspEvent SET SpecsLoaded=RecordsAdded " & _
    "WHERE EventID = Event_Identifier")
With qdf
    .Parameters("RecordsAdded") = lngRecordsAdded
    .Parameters("Event_Identifier") = [Forms]![frmInspEvent]![txtEventId]
    .Execute
End With  

这可以缩短为单行:

If IsNull(DLookup("Vendor", "PurchaseOrder", strFilter)) Then
    strVendor = "None"
Else
    strVendor = DLookup("Vendor", "PurchaseOrder", strFilter)
End If