Dreamweaver
Well-known member
- Local time
- Today, 10:53
- Joined
- Nov 28, 2005
- Messages
- 2,466
his is used with the beforeupdate of the form
This is just one way of doing this.
You can add as many options as you like just copy from the "If" to "End If" for one field and past/Update to suit.
I did not write this function but it was never taged with the developer
This is just one way of doing this.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo HandleErr
Cancel = Not TestRecord
HandleExit:
Exit Function
HandleErr:
Select Case Err.Number
Case 2501 'Cancel = True
Exit Function
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Resume HandleExit
Resume
End Select
End Sub
You can add as many options as you like just copy from the "If" to "End If" for one field and past/Update to suit.
Code:
Function TestRecord() As Boolean
Dim Txt As String
Dim Er As Boolean
On Error GoTo HandleErr
Er = False
If IsNothing(Me![STxt_Question]) Then
Txt = Txt & vbCrLf & "You must add a question"
Er = True
End If
If IsNothing(Me![STxt_Answer]) Then
Txt = Txt & vbCrLf & "A Question requires a answer"
Er = True
End If
If IsNothing(Me![SCbo_CategoryID]) Then
Txt = Txt & vbCrLf & "Category is empty"
Er = True
End If
If IsNothing(Me![SCbo_Qstatus]) Then
Txt = Txt & vbCrLf & "Please select a status"
Er = True
End If
If IsNothing(Me![SCbo_LevelID]) Then
Txt = Txt & vbCrLf & "Please select a level for this question"
Er = True
End If
If Er = True Then
MsgBox "The following data errors have been found" & Txt & vbCrLf & _
"These errors must be corrected before I can save this record", vbCritical + vbOKOnly, "Incomplete Record"
TestRecord = False
Else
TestRecord = True
End If
HandleExit:
Exit Function
HandleErr:
Select Case Err.Number
Case 2501 'Cancel = True
Exit Function
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Resume HandleExit
Resume
End Select
End Function
I did not write this function but it was never taged with the developer
Code:
Function IsNothing(varToTest As Variant) As Boolean
'Function found on web
On Error GoTo HandleErr
IsNothing = True
Select Case VarType(varToTest)
Case vbEmpty
Exit Function
Case vbNull
Exit Function
Case vbBoolean
If varToTest Then IsNothing = False
Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency
If varToTest <> 0 Then IsNothing = False
Case vbDate
IsNothing = False
Case vbString
If (Len(varToTest) <> 0 And varToTest <> " ") Then IsNothing = False
End Select
HandleExit:
Exit Function
HandleErr:
Select Case Err.Number
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
Resume HandleExit
Resume
End Select
End Function
Last edited: