Hello,
The below code I have in a module and is called by a form at Before Update. It checks the integrity of the data entered (or lack thereof) in a form. If they do not follow the guidlines and enter in the data incorrectly, it should make a msgbox with a warning message and stop the record from being saved....What is happening currently is that the message box pops up, but as soon as you click OK, it accepts the record and goes on to another one. So somewhere in here, it gives the message, but it's not stopping you from saving the data.
Thanks,
---roystreet
Code In The Module:
Public Function ExitIntegrityCheck(frm As Form) As Integer
'Error handler included below requires specific integrity requirements be met
'String can not be 0, Null, Alpha, nor less than 4 characters
'Special Note: This code will insert leading zeros for user so as long as they type in one numeric string you will
'Always have 4 characters
'
'This code also concatenates the values eliminating the need to have it in the BeforeUpdate on the Forms code
'If string follows integrity requirements then end code - Else Error Message
'If string is 0 then below error - Else second error
Dim finalvalue As String
If IsNumeric(frm!Unique_Number) Then 'false if null or alpha
If frm!Unique_Number > 0 And frm!Unique_Number < 10000 Then
frm!Unique_Number = Right("0000" & Trim(frm!Unique_Number), 4) 'trim added to remove spaces
Else
MsgBox " The Regional Number Can NOT END With a 0 Value ", vbExclamation, ":::: Regional Number Not Complete :::: (Error: 150)"
Cancel = True
End If
'If string is alpha or does not have four numeric characters or is Null then below error
Else
MsgBox "The Regional Number MUST END With Four Numeric Characters and Can Not Be Null (Blank)", vbExclamation, ":::: Regional Number Not Complete :::: (Error: 125)"
Cancel = True
End If
'Error handler included below requiring an alpha-numeric string be inserted
'This will not allow the case to be updated (inserted as a new record in table) until all integrity rules are met
'If string is Null then error message - Else accept
Dim Msg As String, Stlye As Integer, Title As String
If IsNull(frm!Employee_Name) Then
Msg = "You MUST Enter In The Employees Name - " & DL & _
"This field is Required"
Style = vbExclamation + vbOKOnly
Title = ":::: Employee Name Not Complete :::: (Error: 175)"
MsgBox Msg, Style, Title
Cancel = True
End If
End Function
The below code I have in a module and is called by a form at Before Update. It checks the integrity of the data entered (or lack thereof) in a form. If they do not follow the guidlines and enter in the data incorrectly, it should make a msgbox with a warning message and stop the record from being saved....What is happening currently is that the message box pops up, but as soon as you click OK, it accepts the record and goes on to another one. So somewhere in here, it gives the message, but it's not stopping you from saving the data.
Thanks,
---roystreet
Code In The Module:
Public Function ExitIntegrityCheck(frm As Form) As Integer
'Error handler included below requires specific integrity requirements be met
'String can not be 0, Null, Alpha, nor less than 4 characters
'Special Note: This code will insert leading zeros for user so as long as they type in one numeric string you will
'Always have 4 characters
'
'This code also concatenates the values eliminating the need to have it in the BeforeUpdate on the Forms code
'If string follows integrity requirements then end code - Else Error Message
'If string is 0 then below error - Else second error
Dim finalvalue As String
If IsNumeric(frm!Unique_Number) Then 'false if null or alpha
If frm!Unique_Number > 0 And frm!Unique_Number < 10000 Then
frm!Unique_Number = Right("0000" & Trim(frm!Unique_Number), 4) 'trim added to remove spaces
Else
MsgBox " The Regional Number Can NOT END With a 0 Value ", vbExclamation, ":::: Regional Number Not Complete :::: (Error: 150)"
Cancel = True
End If
'If string is alpha or does not have four numeric characters or is Null then below error
Else
MsgBox "The Regional Number MUST END With Four Numeric Characters and Can Not Be Null (Blank)", vbExclamation, ":::: Regional Number Not Complete :::: (Error: 125)"
Cancel = True
End If
'Error handler included below requiring an alpha-numeric string be inserted
'This will not allow the case to be updated (inserted as a new record in table) until all integrity rules are met
'If string is Null then error message - Else accept
Dim Msg As String, Stlye As Integer, Title As String
If IsNull(frm!Employee_Name) Then
Msg = "You MUST Enter In The Employees Name - " & DL & _
"This field is Required"
Style = vbExclamation + vbOKOnly
Title = ":::: Employee Name Not Complete :::: (Error: 175)"
MsgBox Msg, Style, Title
Cancel = True
End If
End Function