arnelgp
..forever waiting... waiting for jellybean!
- Local time
- Tomorrow, 06:32
- Joined
- May 7, 2009
- Messages
- 20,186
i told you to Add the variable?
Code:
Option Compare Database
Option Explicit
Dim thisID As Long
Private Sub DocumentNo_BeforeUpdate(Cancel As Integer)
Cancel = withDup()
If Cancel Then
If MsgBox("Document and Revision already exists!" & vbCrLf & vbCrLf & _
"Do you want to go to the record?", vbInformation + vbYesNo + vbDefaultButton2) = vbYes Then
Me.Undo
Me.TimerInterval = 100
End If
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = Len(Me!DocumentNo & "") = 0 Or Len(Me!Rev & "") = 0
If Cancel Then
MsgBox "Document and/or Revision is missing!"
End If
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.CPPCategory.ColumnHidden = True
End Sub
Private Sub Form_Timer()
Dim rs As DAO.Recordset
'immediately kill the timer
Me.TimerInterval = 0
Set rs = Me.RecordsetClone
Set rs = rs.Clone
rs.FindFirst "ID = " & thisID
Me.Bookmark = rs.Bookmark
Set rs = Nothing
End Sub
Private Sub Rev_BeforeUpdate(Cancel As Integer)
Call DocumentNo_BeforeUpdate(Cancel)
End Sub
Private Function withDup() As Boolean
Dim retBool As Boolean
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
Set rs = rs.Clone
thisID = 0
If rs.RecordCount < 1 Then
GoTo exit_function
End If
If Len(Me!DocumentNo & "") <> 0 And Len(Me!Rev & "") <> 0 Then
With rs
.FindFirst "[DocumentNo] = '" & Me![DocumentNo] & "' And " & _
"[Rev] = '" & Me![Rev] & "' And " & _
"Nz([CPPCategory],'@') = '" & Nz(Me![CPPCategory], "@") & "' And " & _
"Nz([MainUnit], '@') = '" & Nz(Me![MainUnit], "@") & "' And " & _
"Nz([SECTIONUNIT], '@') = '" & Nz(Me![SectionUnit], "@") & "' And " & _
"Nz([SUBSECTIONUNIT], '@') = '" & Nz(Me![SubSectionUnit], "@") & "' And " & _
"Nz([DOCUMENTTYPE], '@') = '" & Nz(Me![DocumentType], "@") & "'"
If Not .NoMatch Then
thisID = !ID
retBool = True
End If
End With
End If
exit_function:
Set rs = Nothing
withDup = retBool
End Function