Run-time error: The value you entered isn't valid for this field

Run-time error: The value you entered isn't valid for this field

我正在尝试使用子表单更新记录。当我第一次更新时,它会正确更新,但是当我尝试再次更新同一条记录时,出现错误:

Run-time error '-2147352567 (80020009)': The value you entered isn't valid for this field

表格如下

当我单击“编辑”时,所选记录中的信息将填充到相应的文本框中。一旦我更新信息并点击更新,第一次成功更新记录。

当我尝试再次更新同一条记录时,出现上述错误。

这里是 VB 单击编辑时运行的脚本。

Private Sub cmdEdit_Click()
    'Check if data exists in the list
    If Not (Me.frmschoolsub.Form.Recordset.EOF And Me.frmschoolsub.Form.Recordset.BOF) Then
        'get data to text box control
        With Me.frmschoolsub.Form.Recordset
            Me.Schooltxt = .Fields("School_Name")
            Me.Desctxt = .Fields("Description")
            Me.Deantxt = .Fields("Dean")
            Me.Adeantxt = .Fields("Associate_Dean")
            'store id of student in tag
            Me.Schooltxt.Tag = .Fields("School_ID")
            'change caption of button to update
            Me.cmdAdd.Caption = "Update"
            Me.cmdEdit.Enabled = False
        End With
    End If
End Sub

当我单击“调试”时,它会突出显示以下行。

Me.Schooltxt = .Fields("School_Name")

你能帮我确定这里的问题是什么吗?

我发现每次更新后,我都失去了记录的位置。我在更新和重新查询后添加了以下语句

Me.frmschoolsub.Form.Recordset.MoveFirst

以下是代码片段。

    Else
        CurrentDb.Execute "Update School " & _
                " SET School_Name ='" & Me.Schooltxt & "'" & _
                ", Description ='" & Me.Desctxt & "'" & _
                ", Dean ='" & Me.Deantxt & "'" & _
                ", Associate_Dean='" & Me.Adeantxt & "'" & _
                "where School_ID=" & Me.Schooltxt.Tag


    End If
    'Clear the Fields
    cmdClr_Click
    'Refresh the table
    frmschoolsub.Form.Requery
    Me.frmschoolsub.Form.Recordset.MoveFirst

这解决了问题。

发生此错误是因为无法像您那样将表单域引用到文本框。

您可以按照下面的方式进行。

With Me.frmschoolsub.Form.Recordset
     Me.Schooltxt = Forms![<<if you have main form  >>]![frmschoolsub].form![School_Name]