dan-cat
Registered User.
- Local time
- Today, 20:40
- Joined
- Jun 2, 2002
- Messages
- 3,415
Hello,
I'm trying to build my own querydef based on criteria on a form but I am having a slight problem with the SQL.
The function reads like this:
Function BuildSQLString(strSQL As String) As Boolean
Dim strSelect As String
Dim strFrom As String
Dim strWhere As String
strSelect = "s.* "
strFrom = "AllProducts s "
If Forms!MODSearchForm!SBUChk = -1 Then
strWhere = " AND s.SBU = " & Forms!MODSearchForm!SBUCombo
End If
If Forms!MODSearchForm!SICChk = -1 Then
strWhere = strWhere & " AND s.[SIC Codes] = " & Forms!MODSearchForm!IndustryCombo
End If
strSQL = "SELECT " & strSelect
strSQL = strSQL & "FROM " & strFrom
If strWhere <> " " Then strSQL = strSQL & "WHERE " & Mid$(strWhere, 6)
BuildSQLString = True
End Function
It's called like this:
Dim strSQL As String
If Not BuildSQLString(strSQL) Then
MsgBox " There was a problem building the SQL string"
Exit Sub
End If
MsgBox strSQL
CurrentDb.QueryDefs("qryExample").SQL = strSQL
However within the SQL criteria the contents of the field are displayed as [ABC] instead of "ABC".
Can anyone see what I am doing wrong?
Thankyou
Dan
I'm trying to build my own querydef based on criteria on a form but I am having a slight problem with the SQL.
The function reads like this:
Function BuildSQLString(strSQL As String) As Boolean
Dim strSelect As String
Dim strFrom As String
Dim strWhere As String
strSelect = "s.* "
strFrom = "AllProducts s "
If Forms!MODSearchForm!SBUChk = -1 Then
strWhere = " AND s.SBU = " & Forms!MODSearchForm!SBUCombo
End If
If Forms!MODSearchForm!SICChk = -1 Then
strWhere = strWhere & " AND s.[SIC Codes] = " & Forms!MODSearchForm!IndustryCombo
End If
strSQL = "SELECT " & strSelect
strSQL = strSQL & "FROM " & strFrom
If strWhere <> " " Then strSQL = strSQL & "WHERE " & Mid$(strWhere, 6)
BuildSQLString = True
End Function
It's called like this:
Dim strSQL As String
If Not BuildSQLString(strSQL) Then
MsgBox " There was a problem building the SQL string"
Exit Sub
End If
MsgBox strSQL
CurrentDb.QueryDefs("qryExample").SQL = strSQL
However within the SQL criteria the contents of the field are displayed as [ABC] instead of "ABC".
Can anyone see what I am doing wrong?
Thankyou
Dan