Sorry for the cross post from the ADP forum but, I am not sure which forum will be able to address this best.
I am trying to run a SQL function that validates file numbers prior to inserting the row into the table.
Here is the SQL function.
And here is some sample code to show what I am trying to do.
(NON FUNCTIONAL).
The reason for doing this is because the curent VBA code is allowing impropperly formatted file numbers into the tracking table.
Here is the current VBA code just in case.
Thanks
John Fuhrman
Thanks
John Fuhrman
I am trying to run a SQL function that validates file numbers prior to inserting the row into the table.
Here is the SQL function.
Code:
/****** Object: UserDefinedFunction [dbo].[IsFileNumberValid] Script Date: 10/19/2010 10:23:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Function [dbo].[IsFileNumberValid]
(@FileNumber VarChar(15))
Returns Bit
As
Begin
Declare @Prefix VarChar(15)
Declare @IsValid Bit
Select @IsValid = 0,
@Prefix = Left(@FileNumber, PatIndex('%[^a-z.]%', @FileNumber + '1')-1)
If (@FileNumber like '[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @FileNumber like '[a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @FileNumber like '[a-zA-Z][a-zA-Z][a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @FileNumber like '[a-zA-Z][a-zA-Z][a-zA-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR @FileNumber like '.BOX.END.')
If Exists(Select 1 from tblFileNumPrefix Where FileNumPrefix = @Prefix)
Set @IsValid = 1
Return @IsValid
End
And here is some sample code to show what I am trying to do.
(NON FUNCTIONAL).
Code:
If DoCmd.OpenFunction(IsFileNumberValid,acViewNormal,acReadOnly) me.FileNumber <> 1 Then
Cancel = True
BeepWhirl
strResult = MsgBox("The File Number you have Entered is Invalid." & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!")
Select Case strResult
Case vbOK, vbRetry, vbYes, vbNo
Me.Undo
Exit Sub
Case vbCancel, vbAbort, vbIgnore
Exit Sub
Case Else
Exit Sub
End Select
End If
The reason for doing this is because the curent VBA code is allowing impropperly formatted file numbers into the tracking table.
Here is the current VBA code just in case.
Code:
On Error GoTo Err_Handler
Dim TrackingDate As Date
Dim dl As String
dl = vbNewLine & vbNewLine
Me.TrackingDate = Now
Select Case Len(Me.FileNumber)
Case Is < 7
Cancel = True
BeepWhirl
MsgBox Me.FileNumber & " is not a Valid File Number" & dl & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!"
Me.Undo
Exit Sub
Case 8 To 13
If IsAlpha(left(Me.FileNumber, 3)) = True Then
Select Case UCase(left(Me.FileNumber, 3))
Case "SRC", "LIN", "WAC", "EAC", "MSC"
If IsNumeric(Mid(Me.FileNumber, 4)) = True Then
'Continue
Else
Cancel = True
BeepWhirl
strResult = MsgBox(Me.FileNumber & " is not a Valid File Number" & dl & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!")
Select Case strResult
Case vbOK, vbRetry, vbYes, vbNo
Me.Undo
Exit Sub
Case vbCancel, vbAbort, vbIgnore
Exit Sub
Case Else
Exit Sub
End Select
End If
Case Else
Cancel = True
BeepWhirl
strResult = MsgBox(Me.FileNumber & " is not a Valid File Number" & dl & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!")
Select Case strResult
Case vbOK, vbRetry, vbYes, vbNo
Me.Undo
Exit Sub
Case vbCancel, vbAbort, vbIgnore
Exit Sub
Case Else
Exit Sub
End Select
End Select
ElseIf IsAlpha(left(Me.FileNumber, 1)) = True Then
Select Case UCase(left(Me.FileNumber, 1))
Case "A", "T", "S", "W", "C"
If IsNumeric(Mid(Me.FileNumber, 2)) = True Then
'Continue
Else
Cancel = True
BeepWhirl
strResult = MsgBox(Me.FileNumber & " is not a Valid File Number" & dl & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!")
Select Case strResult
Case vbOK, vbRetry, vbYes, vbNo
Me.Undo
Exit Sub
Case vbCancel, vbAbort, vbIgnore
Exit Sub
Case Else
Exit Sub
End Select
End If
Case Else
Cancel = True
BeepWhirl
strResult = MsgBox(Me.FileNumber & " is not a Valid File Number" & dl & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!")
Select Case strResult
Case vbOK, vbRetry, vbYes, vbNo
Me.Undo
Exit Sub
Case vbCancel, vbAbort, vbIgnore
Exit Sub
Case Else
Exit Sub
End Select
End Select
ElseIf UCase(Me.FileNumber) = UCase(".box.end.") Then
'End of box processing
Else
Cancel = True
BeepWhirl
strResult = MsgBox(Me.FileNumber & " is not a Valid File Number" & dl & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!")
Select Case strResult
Case vbOK, vbRetry, vbYes, vbNo
Me.Undo
Exit Sub
Case vbCancel, vbAbort, vbIgnore
Exit Sub
Case Else
Exit Sub
End Select
End If
Case Is > 13
Cancel = True
BeepWhirl
MsgBox Me.FileNumber & " is not a Valid File Number" & dl & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!"
Me.Undo
Exit Sub
End Select
If DCount("*", "tblTrackingTable", "FileNumber='" & Me!FileNumber & "' AND BoxNumber='" & Me!BoxNumber & "'") >= 1 Then
Cancel = True
BeepWhirl
strResult = MsgBox("You have attempted to enter a duplicate" & _
"File Number for " & Me.BoxNumber.Value & vbCrLf & _
"Please Correct the File Number ...", _
vbExclamation + vbOKOnly, _
"ERROR!")
Select Case strResult
Case vbOK, vbRetry, vbYes, vbNo
Me.Undo
Exit Sub
Case vbCancel, vbAbort, vbIgnore
Exit Sub
Case Else
Exit Sub
End Select
End If
endit:
Exit Sub
Err_Handler:
If StandardErrors(Err) = False Then
BeepWhirl
MsgBox Err & ": " & Err.Description
End If
Resume endit
End Sub
Thanks
John Fuhrman
Thanks
John Fuhrman