I'm trying to use an ADO SHAPE COMMAND on a VB6 Data Report however, I keep getting the error invalid 'Expecting SELECT, UPDATE, ..."
Here's the code:
And this is the working source code I followed: (Works fine)
Here's the code:
Code:
Dim cnn As New ADODB.Connection
With cnn
.Provider = "MSDataShape"
.Properties("Data Provider") = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = App.Path & "\data1.mdb" '"database path and name"
.Open
End With
Dim rstRpt As New ADODB.Recordset
Dim cmd As New ADODB.Command
With cmd
.ActiveConnection = cnn
.CommandType = adCmdText
lvRowSel = ListView2.ListItems.Item(sol2).SubItems(2)
Dim strQry As String
strQry = "SELECT 'Table 1' AS strTableID, clientPurchases.qty AS strFld1,clientPurchases.unit AS strFld2, " _
& "clientPurchases.productdesc AS strFld3,clientPurchases.price AS strFld4, " _
& "clientPurchases.discount AS strFld5,clientPurchases.amt AS strFld6 " _
& "FROM clientPurchases " _
& "WHERE clientPurchases.invoiceno='" & lvRowSel & "' AND salereport=" & tVal & " union all"
strQry = strQry & "SELECT 'Table 2' AS strTableID, FinalReturns.qty AS strFld1,FinalReturns.unit AS strFld2, " _
& "FinalReturns.productdesc AS strFld3,FinalReturns.price AS strFld4,FinalReturns.discount AS strFld5, " _
& "FinalReturns.amt AS strFld6 " _
& "FROM FinalReturns " _
& "WHERE FinalReturns.invoiceno='" & lvRowSel & "' order by strTableID"
.CommandText = "SHAPE {" & strQry & "} AS rstGrouped COMPUTE rstGrouped BY strTableID"
End With
rstRpt.CursorLocation = adUseServer
rstRpt.Open cmd, , adOpenKeyset, adLockOptimistic, 8
Code:
Dim rstRpt As New ADODB.Recordset
Dim cn As New ADODB.Connection
With cn
.Provider = "MSDataShape"
.Properties("Data Provider") = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = App.Path & "\TwoTables.mdb" '"database path and name"
.Open
End With
Dim cmd As New ADODB.Command
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
Dim strQry As String
strQry = "SELECT 'Table 1' AS strTableID, Table1_2Tables.Name AS strFld1, Table1_2Tables.Address AS strFld2, Table1_2Tables.City AS strFld3 FROM Table1_2Tables union all "
strQry = strQry & "SELECT 'Table 2' AS strTableID, Table2_2Tables.VehicleName AS strFld1, Table2_2Tables.VehicleModel AS strFld2, Table2_2Tables.YrManufac AS strFld3 FROM Table2_2Tables order by strTableID"
.CommandText = "SHAPE {" & strQry & "} AS rstGrouped COMPUTE rstGrouped BY strTableID"
End With
rstRpt.CursorLocation = adUseServer
rstRpt.Open cmd, , adOpenKeyset, adLockOptimistic, 8