Skip to main content

Date Field Type Macro with custom date format


QAID # 398 Published

Question / Problem:

How can I change my Date Field Type Macro to allow me to input my own date format?

Answer / Solution:

Kofax Capture uses multiple checks to verify the date format and change it to the regional settings format that is specified for your computer. However, if you would like to create your own format, below is a sample Field Type Macro that allows you to do this:

Please note this line:

datecompare = format(EnteredValue,"##/##/##")

This will format the date to the format specified. Please be sure to review the SBL online help for more information on using the format command and possible date format combinations.

REM ========================================================================
REM Field Macro Name: Date_NoVerify
REM ------------------------------------------------------------------------
            ' Uncomment the global definition below if the
            ' scripts to have read-only access to the
            ' index field's Confidence Level (CL).
'Global KfxCL_KFX_Date_NoVerify As String
            ' Index field value.
Global Kfx_KFX_Date_NoVerify As String
            '===== SQL_DATE Procedures

' Return codes are defined by the document class customization script.
            '----- _KFX_Date_NoVerify default value: todays's date
Function Pre_KFX_Date_NoVerify() As Integer
    On Error GoTo Failure
    'With Capture 3.0, default values are set in the Administration module.
    'Enable and modify the following line to override the Administration-set default
    'If (Kfx_KFX_Date_NoVerify = "") Then Kfx_KFX_Date_NoVerify = Format$(Now, "ddddd")
    Pre_KFX_Date_NoVerify = NoError
    Exit Function
    Pre_KFX_Date_NoVerify = FatalError
    Exit Function
    End Function
            '----- _KFX_Date_NoVerify validation: checks for valid
            '----- date. Format of validated string must
            '----- match WIN.INI sShortDate format setting.

Function Post_KFX_Date_NoVerify( EnteredValue As String ) As Integer
    On Error GoTo Failure
    Dim dateCompare as string     '*** Temporily store the date value for comparison

    EnteredValue = Trim(EnteredValue)
    '*** Formats the numeric into date format temporarily
    dateCompare = format(EnteredValue,"##/##/##")
    If Not IsDate(datecompare) Then GoTo Failure
    '*** Comment out to change to compare on temp value
    'If Not IsDate(EnteredValue) Then GoTo Failure
    '*** will need to remove the datevalue function
    'Kfx_KFX_Date_NoVerify = CStr( DateValue(EnteredValue) )
    Kfx_KFX_Date_NoVerify = dateCompare
    Post_KFX_Date_NoVerify = NoError
    Exit Function
    Post_KFX_Date_NoVerify = ValidationError
    Exit Function
End Function
            '----- _KFX_Date_NoVerify format
'*** Don't forget to modify the format function so Ascent does not try to turn the value into
'*** a date format for display

Function Fmt_KFX_Date_NoVerify() As String
    'The On Error is here to trap unexpected exceptions, however this function
    'does not return a status.
    On Error GoTo Failure
    If ( Kfx_KFX_Date_NoVerify = "" ) Then GoTo Failure
    '*** need to remove the datevalue
    ' Fmt_KFX_Date_NoVerify = Format( DateValue(Kfx_KFX_Date_NoVerify) )
    Fmt_KFX_Date_NoVerify = Kfx_KFX_Date_NoVerify
    Exit Function
    Fmt_KFX_Date_NoVerify = Kfx_KFX_Date_NoVerify
End Function

Applies to:

Product Version