在MS Access中选择ListBox

时间:2014-04-05 15:11:55

标签: vba ms-access

亲爱的,我需要一点帮助。我有一个表单,我有列表框,并选择列表框我填写表格中的一些字段和子表单。 我想要实现的是子窗体不应该有0条记录。 所以我有一个控件在哪里检查记录集是否为0并弹出一条消息但是exit sub没有帮助,用户可以继续下一条记录。

    Private Sub lstRev_BeforeUpdate(Cancel As Integer)
    Dim DataConn10 As New ADODB.Recordset
    Dim Comm10 As String
    Set Conn = CurrentProject.Connection
    Comm10 = " SELECT tblLIVE.SID " & _
   " FROM tblLIVE " & _
   " WHERE tblLIVE.CID = " & Me.txtCID & " And tblLIVE.PID =
   " & Me.txtPIDRev & " And tblLIVE.MNumber = '" & Me.txtSMNum & "'"
    DataConn10.Open Comm10, Conn, adOpenKeyset, adLockOptimistic
    If DataConn10.RecordCount = 0 And Not IsNull(Me.txtMIDRev) Then
    Dim x As Integer
    x = MsgBox("Are sure that you want to leave the form without adding Line in subform.    If you press yes Rev will be deleted. If you press No please enter Line", vbYesNo)
    If x = vbYes Then
   MsgBox "Delete"
  Else
  MsgBox "EnterSOV"
  'Here I need something to tell him to stay in the same record :(
  DataConn10.Close
  Exit Sub
  End If
  End If
  End Sub

1 个答案:

答案 0 :(得分:0)

您可以添加Cancel=True以防止更新前方法完成。只需在Exit Sub之前添加此内容。