skorpionkz
Well-known Member
- Joined
- Oct 1, 2013
- Messages
- 1,171
- Office Version
- 2016
Hi All,
I am building VBA tool and need to incorporate report into it. Data is recorded in Access database.
User will pick status of project and project code list to see in the Report.
I build SQL which works in Access query, but fails in VBA
sample query
Any ideas how to force it to work in VBA?
Thank you,
I am building VBA tool and need to incorporate report into it. Data is recorded in Access database.
User will pick status of project and project code list to see in the Report.
I build SQL which works in Access query, but fails in VBA
sample query
Code:
SELECT * FROM Key_table WHERE (Status = 'Submitted') AND (LookUp_Key LIKE 'PRJ0001*' OR LookUp_Key LIKE 'PRJ0002*')
Any ideas how to force it to work in VBA?
Code:
Private Sub LoadKeyTable()
Dim myConnection As New ADODB.Connection
Dim v_Item As Variant
Dim str_SQL As String
Dim str_List As String
Dim arr_List As Variant
str_List = uf_Main.txt_ReportList
If Not str_List = Empty Then
arr_List = Split(str_List, ",")
str_List = Empty
For Each v_Item In arr_List
If Not v_Item = Empty Then
If str_List = Empty Then
str_List = "LookUp_Key LIKE '" & v_Item & "*'"
Else
str_List = str_List & " OR LookUp_Key LIKE '" & v_Item & "*'"
End If
End If
Next v_Item
End If
str_SQL = "SELECT * FROM " & DB.KEYTABLE
str_SQL = str_SQL & " WHERE (Status = '" & PBL.LoadList & "')"
If Not str_List = Empty Then str_SQL = str_SQL & " AND (" & str_List & ")"
Set myConnection = ConnectTo_IPSDB
Set PBL.RecordSet = myConnection.Execute(str_SQL)
RecordSetToClass DB.KEYTABLE
myConnection.Close
Set PBL.RecordSet = Nothing
Set myConnection = Nothing
End Sub
Thank you,