Does anyone know how I can simplify the following sub routine? Please let me know. I am just finding the subroutine to be too unreadable, it works and everything but it is just too cumbersome for those who don't know what is going on with it. At the bottom I have included the Function that I am using in the module which is referenced in the sub routine:
Sub BuildRecSource()
' subroutine in expression
Dim getRowSce As String
Dim getOrdrcls As String
Dim getWhrcls As String
Dim getCondi As String
Dim getCond As String
Dim stdCod As String
Dim stdCodi As String
Dim stdCdm As String
Dim stdCCm As String
Dim stdWhrCls As String
If (Nz(Forms![daily_list]![List4])) = "" Then
If (Forms![daily_list]![List9]) = "All" Then
stdCdm = ""
stdCCm = ""
stdWhrCls = freedajuice("[wrk_ordr]", "", "", " WHERE "
Else
stdWhrCls = " WHERE "
If (Nz(Forms![daily_list]![wrk_ordr])) = "" Then
stdCdm = ""
stdCCm = ""
Else
stdCod = " AND "
stdCdm = "("
stdCCm = "
"
End If
End If
Else
stdWhrCls = " WHERE "
stdCod = " AND "
If (Nz(Forms![daily_list]![wrk_ordr])) = "" Then
stdCodi = ""
If (Forms![daily_list]![List9]) = "All" Then
stdCdm = ""
stdCCm = ""
Else
stdCdm = "("
stdCCm = "
"
End If
Else
stdCodi = " AND "
stdCdm = "("
stdCCm = "
"
End If
End If
getRowSce = "Select DISTINCTROW daily.id, daily.techid, daily.dt, daily.tm_in, daily.tm_out, daily.addr, daily.wrk_ordr_num, daily.dscrpt, daily.cde FROM daily"
getWhrcls = stdWhrCls & stdCdm & freedajuice("List4", "", "", "((daily.dt)=" & "#" & [Forms]![daily_list]![List4] & "#)"
getCondi = freedajuice("wrk_ordr", "", "", stdCodi & "(daily.[wrk_ordr_num])='" & ([Forms]![daily_list]![wrk_ordr]) & "'"
getCond = freedajuice("List9", "All", "", stdCod & "(daily.techid)='" & ([Forms]![daily_list]![List9]) & "'"
getOrdrcls = stdCCm & " ORDER BY daily.techid, daily.wrk_ordr_num;"
List6.RowSource = getRowSce & getWhrcls & getCondi & getCond & getOrdrcls
End Sub
Function freedajuice(ByVal strjuci As String, strcd As String, strtru As String, strfls As String) As Variant
' function referred to in subroutine
Dim gstrfld As String
gstrfld = Nz(Forms("daily_list"
(strjuci))
freedajuice = IIf((gstrfld) = strcd, strtru, strfls)
End Function
Thank you,
Noel
Sub BuildRecSource()
' subroutine in expression
Dim getRowSce As String
Dim getOrdrcls As String
Dim getWhrcls As String
Dim getCondi As String
Dim getCond As String
Dim stdCod As String
Dim stdCodi As String
Dim stdCdm As String
Dim stdCCm As String
Dim stdWhrCls As String
If (Nz(Forms![daily_list]![List4])) = "" Then
If (Forms![daily_list]![List9]) = "All" Then
stdCdm = ""
stdCCm = ""
stdWhrCls = freedajuice("[wrk_ordr]", "", "", " WHERE "
Else
stdWhrCls = " WHERE "
If (Nz(Forms![daily_list]![wrk_ordr])) = "" Then
stdCdm = ""
stdCCm = ""
Else
stdCod = " AND "
stdCdm = "("
stdCCm = "
End If
End If
Else
stdWhrCls = " WHERE "
stdCod = " AND "
If (Nz(Forms![daily_list]![wrk_ordr])) = "" Then
stdCodi = ""
If (Forms![daily_list]![List9]) = "All" Then
stdCdm = ""
stdCCm = ""
Else
stdCdm = "("
stdCCm = "
End If
Else
stdCodi = " AND "
stdCdm = "("
stdCCm = "
End If
End If
getRowSce = "Select DISTINCTROW daily.id, daily.techid, daily.dt, daily.tm_in, daily.tm_out, daily.addr, daily.wrk_ordr_num, daily.dscrpt, daily.cde FROM daily"
getWhrcls = stdWhrCls & stdCdm & freedajuice("List4", "", "", "((daily.dt)=" & "#" & [Forms]![daily_list]![List4] & "#)"
getCondi = freedajuice("wrk_ordr", "", "", stdCodi & "(daily.[wrk_ordr_num])='" & ([Forms]![daily_list]![wrk_ordr]) & "'"
getCond = freedajuice("List9", "All", "", stdCod & "(daily.techid)='" & ([Forms]![daily_list]![List9]) & "'"
getOrdrcls = stdCCm & " ORDER BY daily.techid, daily.wrk_ordr_num;"
List6.RowSource = getRowSce & getWhrcls & getCondi & getCond & getOrdrcls
End Sub
Function freedajuice(ByVal strjuci As String, strcd As String, strtru As String, strfls As String) As Variant
' function referred to in subroutine
Dim gstrfld As String
gstrfld = Nz(Forms("daily_list"
freedajuice = IIf((gstrfld) = strcd, strtru, strfls)
End Function
Thank you,
Noel