stevecrowhurst
IS-IT--Management
Could you guys run your eye over the function below and give me a few tips on the WHERE clause.
I'm trying to construct a QBF and I'm fighting a very stringent deadline. Thanks for the help.
Function BuildSQLString(ByRef strSQL As String) As Boolean
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
strSELECT = "SELECT s.*.*" 'set the columns to return results from
'(all columns in this case)
'set an alias "h" for HRBaseTbl
strFROM = "FROM HRBaseTbl As h "
If chkFirstNameID Then
'check for 2nd or more WHERE term
If strWHERE <> " " Then strWHERE = strWHERE & " AND "
strWHERE = strWHERE & "h.HRID = " & cboFirstNameID
End If
If chkSurnameID Then
'check for 2nd or more WHERE term
If strWHERE <> " " Then strWHERE = strWHERE & " AND "
strWHERE = strWHERE & "h.HRID = " & cboSurnameID
End If
strSQL = strSELECT & strFROM
If strWHERE <> " " Then strSQL = strSQL & "WHERE " & strWHERE
BuildSQLString = True
End Function
I'm trying to construct a QBF and I'm fighting a very stringent deadline. Thanks for the help.
Function BuildSQLString(ByRef strSQL As String) As Boolean
Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String
strSELECT = "SELECT s.*.*" 'set the columns to return results from
'(all columns in this case)
'set an alias "h" for HRBaseTbl
strFROM = "FROM HRBaseTbl As h "
If chkFirstNameID Then
'check for 2nd or more WHERE term
If strWHERE <> " " Then strWHERE = strWHERE & " AND "
strWHERE = strWHERE & "h.HRID = " & cboFirstNameID
End If
If chkSurnameID Then
'check for 2nd or more WHERE term
If strWHERE <> " " Then strWHERE = strWHERE & " AND "
strWHERE = strWHERE & "h.HRID = " & cboSurnameID
End If
strSQL = strSELECT & strFROM
If strWHERE <> " " Then strSQL = strSQL & "WHERE " & strWHERE
BuildSQLString = True
End Function