VBA, MS Access MS Access в примерах

Удаление записей по выделенным строкам подчиненной формы (02)

Внешний модуль:

Option Compare Database
Option Explicit

Public TopLine As Long
Public LineNo As Long


Подчинённая форма:

Private Sub Form_Open(Cancel As Integer)
    TopLine = 0
    LineNo = 0
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    TopLine = Me.SelTop
    LineNo = Me.SelHeight
End Sub


Основная форма:

Private Sub Form_Open(Cancel As Integer)
    TopLine = 0
    LineNo = 0
End Sub


Кнопка Btn_Delete01 - первый вариант:

Private Sub Btn_Delete01_Click()
Dim I As Integer, sVal$
    If LineNo = 0 Then MsgBox "No Record Selected !", vbExclamation: Exit Sub
    If MsgBox("Confirm Delete " & LineNo & " Sizes ?", _
        vbQuestion + vbDefaultButton2 + vbYesNo, "Confirm Delete") = vbYes Then
        Me.frmRbQuotation_Sub.Form.AllowAdditions = False
        For I = TopLine To LineNo + TopLine - 1
            Me.frmRbQuotation_Sub.Form.SelTop = I
            sVal = sVal & ", " & Me.frmRbQuotation_Sub.Form!RecID
        Next
    End If
    
    If Len(sVal) > 2 Then
        sVal = Mid(sVal, 3)
        'Deleting selected records :
        sVal = "DELETE * FROM Temp_Quotation WHERE RecID IN (" & sVal & ")"
        CurrentDb.Execute sVal
        Me.frmRbQuotation_Sub.Form.Requery
    End If
    
    TopLine = 0
    LineNo = 0
    
End Sub


Кнопка Btn_Delete02 - второй вариант:

Private Sub Btn_Delete02_Click()
''''''I had to recreate the form, also added a counter type field for tracking
Dim I As Integer
    If LineNo = 0 Then MsgBox "No Record Selected !", vbExclamation: Exit Sub
    If MsgBox("Confirm Delete " & LineNo & " Sizes ?", vbQuestion + vbDefaultButton2 + vbYesNo, "Confirm Delete") = vbYes Then
        Me!frmRbQuotation_Sub.Form.AllowAdditions = False
    ''''''they are always deleted in reverse order''
        For I = LineNo + TopLine - 1 To TopLine Step -1
        Debug.Print I; Me!frmRbQuotation_Sub.Form.QNo
            Me!frmRbQuotation_Sub.Form.SelTop = I
            DoCmd.SetWarnings False
            Me!frmRbQuotation_Sub.SetFocus
            RunCommand acCmdDeleteRecord
            DoCmd.SetWarnings True
        Next
    End If
    Me!frmRbQuotation_Sub.Form.Requery
    TopLine = 0
    LineNo = 0
End Sub

Picture




Скачать

MSA-2007 и выше ( 93 kB) Пример


Назад ToTop
L.E. 25.03.2022
Рейтинг@Mail.ru