How to a function from a query
Is there a way to call a function from a query criteria , for example let assume we have this function below:
Function pBuildSQLWhereFormat(pvarF ldValue As Variant) As String
If Not IsDate(pvarFldValue) Then
' For example, some default value.
pvarFldValue = Date
EndIf
pBuildSQLWhereFormat = "'" & Format(DateValue(pvarFldVa lue), "yyyy\/mm\/dd") & "'"
End Function
Below is a parameter query form
Between [Forms]![frmsalesorder].[t xtstartdat e] And [Forms]![frmsalesorder].[t xtstartEnd date]
What if I call the function above like below:
pBuildSQLWhereFormat(Betwe en [Forms]![frmsalesorder].[t xtstartdat e]) And pBuildSQLWhereFormat( [Forms]![frmsalesorder].[t xtstartEnd date])
Am right or wrong????????????
Regards
Chris
Function pBuildSQLWhereFormat(pvarF
If Not IsDate(pvarFldValue) Then
' For example, some default value.
pvarFldValue = Date
EndIf
pBuildSQLWhereFormat = "'" & Format(DateValue(pvarFldVa
End Function
Below is a parameter query form
Between [Forms]![frmsalesorder].[t
What if I call the function above like below:
pBuildSQLWhereFormat(Betwe
Am right or wrong????????????
Regards
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DECLARE
v_DATE_START DATE;
v_DATE_END DATE;
--Then use below code to convert required format.
--you may need to check is the input is not null and valid date or not . or use exception block
--raise_application_error( -20001, :txtstartdate);
v_DATE_START := TO_DATE(:txtstartdate, 'YYYY/MM/DD');
v_DATE_END := TO_DATE(:txtstartEnddate, 'YYYY/MM/DD');
select * from table_name where column_name between v_DATE_START and v_DATE_END ;
v_DATE_START DATE;
v_DATE_END DATE;
--Then use below code to convert required format.
--you may need to check is the input is not null and valid date or not . or use exception block
--raise_application_error(
v_DATE_START := TO_DATE(:txtstartdate, 'YYYY/MM/DD');
v_DATE_END := TO_DATE(:txtstartEnddate, 'YYYY/MM/DD');
select * from table_name where column_name between v_DATE_START and v_DATE_END ;
Plus, if you give a valid instruction as parameter, the function will recieve its result (in your case, probably a boolean).
Ehence why you should avoid variant type as parameters (unless no other choice is possible).