删除子表单中的选定记录(查询)

时间:2012-03-12 17:33:26

标签: ms-access

我的主窗体包含来自六个表的查询的子窗体,如何在用户选择子窗体中的记录时删除记录(在这六个表中也删除该记录)。我有这个使用listbox之前有查询,但我喜欢列表框上的子表单格式。以下是我从列表框中删除记录所做的工作:

Option Compare Database

Private Sub Delete_Record_Click()  
    If IsNull(Me.List10) Then   
         MsgBox "Please select a record from the list to delete", vbCritical  
    Else  

        DoCmd.SetWarnings False
            If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbDefaultButton2 + vbCritical, "Warning") = vbYes Then
                    DoCmd.RunSQL "Delete * from Ref Where Ref.Record_Num=" & Me.List10
                    DoCmd.RunSQL "Delete * from S_Properties Where S_Properties.Record_Num=" & Me.List10
                    DoCmd.RunSQL "Delete * from C_Type Where C_Type.Record_Num=" & Me.List10
                    DoCmd.RunSQL "Delete * from C_Measurement Where C_Measurement.Record_Num=" & Me.List10
                    DoCmd.RunSQL "Delete * from C Where C.Record_Num=" & Me.List10
                    DoCmd.RunSQL "Delete * from C_Position Where C_Position.Record_Num=" & Me.List10
                    Me.List10.Requery
            End If
            DoCmd.SetWarnings True

   End If End Sub

我尝试了以下代码,但没有奏效: 我在S_properties

收到错误3075错误的运算符
Option Compare Database

 Dim db As Database
 Dim sSQL As String
Private Sub Delete_Record_Click()
    If IsNull(Me.Child15) Then
       MsgBox "Please select a record from the list to delete", vbCritical
    Else

        DoCmd.SetWarnings False
            If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbDefaultButton2 + vbCritical, "Warning") = vbYes Then
                    DoCmd.RunSQL ("Delete * from Ref Where Ref.Record_Num=" & Me.[Child15].Form![Record_Num] & ";")
                    DoCmd.RunSQL ("Delete * from S_Properties Where S_Properties.Record_Num=" & Me.[Child15].Form![Record_Num] & ";")
                    DoCmd.RunSQL ("Delete * from C_Type Where C_Type.Record_Num=" & Me.[Child15].Form![Record_Num] & ";")
                    DoCmd.RunSQL ("Delete * from C_Measurement Where C_Measurement.Record_Num=" & Me.[Child15].Form![Record_Num] & ";")
                    DoCmd.RunSQL ("Delete * from C Where C.Record_Num=" & Me.[Child15].Form![Record_Num] & ";")
                    DoCmd.RunSQL ("Delete * from C_Position Where C_Position.Record_Num=" & Me.[Child15].Form![Record_Num] & ";")
                    Me.Child15.Requery
            End If
            DoCmd.SetWarnings True

   End If
End Sub

0 个答案:

没有答案