尝试将字段从一个表更新到另一个表

时间:2014-04-15 19:15:49

标签: vba ms-access ms-access-2010

我正在尝试创建已完成任务的列表,因此当用户完成任务时,它将在另一个表中填充信息。单击MarkJob按钮时出现错误,说“编译错误无效使用属性”,然后突出显示“[作业名称] =” 以下是我的代码。


Private Sub MarkButton_Click()

    Dim jname As String
    Dim ent As Integer
    Dim user As String
    Dim tstamp As Date

    jname = Me.[Job Name]
    ent = Me.[Entity]
    user = VBA.Environ("USERNAME") & "@" & VBA.Environ("USERDOMAIN") 
    tstamp = Now

  DoCmd.GoToRecord acDataTable, [Completed Jobs], acNewRec


End Sub

Private Sub MarkJob_Click()
   Dim jname As String
   Dim ent As String
   Dim user As String
   Dim tstamp As Date
   Dim result As String
   Dim tbl As String

tbl = tables.[Completed Jobs]
jname = Me.[Job Name]

If IsNumeric(Me.Entity) Then
     ent = Me.Entity
     Else: ent = 0
     End If

user = VBA.Environ("USERNAME")

tstamp = Now

result = InputBox("Please enter result:  Success, or error with ticket number", "Job Result")

Rem MsgBox jname
Rem MsgBox ent
Rem MsgBox user
Rem MsgBox tstamp
Rem MsgBox result

DoCmd.OpenTable "Completed Jobs", acViewNormal, acAdd
UpdateTable.[Completed Jobs]
    Set [Job Name] = jname
    Set [Entity] = ent
    Set [Time Stamp] = tstamp
    Set [UserId] = user
    Set [result] = result

End Sub

1 个答案:

答案 0 :(得分:0)

尝试替换

DoCmd.OpenTable "Completed Jobs", acViewNormal, acAdd
UpdateTable.[Completed Jobs]
    Set [Job Name] = jname
    Set [Entity] = ent
    Set [Time Stamp] = tstamp
    Set [UserId] = user
    Set [result] = result

使用

Dim rsCompleted As Recordset
Set rsCompleted = CurrentDb.OpenRecordset("Completed Jobs")
With rsCompleted
    .AddNew
    ![Job Name] = jname
    ![Entity] = ent
    ![Time Stamp] = tstamp
    ![UserId] = user
    ![result] = result
    .Update
End With