I am using ADO to retrieve records from an MS ACCESS DB in Excel. All my queries work fine but I am having problems with subqueries. My subqueries work fine in ACCESS but when I execute them via ADO I get the following error message:'"The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect".
I hope someone can help me with the correct syntax. Alternatively I was thinking of creating a view in ACCESS but that seems not possible.
Help would much appreciated!
PHP Code:
Sub retrieve_loan_details_test()
Dim Provider As String Dim Source As String Dim sConn As String Dim sSql As String Dim rep_per As Date Dim LB, UB As Long
Dim cnPubs As ADODB.Connection Dim rsPubs As ADODB.Recordset Set cnPubs = New ADODB.Connection Set rsPubs = New ADODB.Recordset
The Datediff function does indeed not work but I think I will be able to find an SQL alternative.
My main problem is the subquery; I have spend most of the day on searching for alternatives but didnt manage to find one.
Do I need to change the syntax for the subquery ((SELECT appID, min(prepdate) as min FROM Prep_input where fullpartial = 'Full' group by appID) b) or is there some other way to do this?
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
Hi , I am using subquery for Retrieve Next record date . My subqueries work fine in ACCESS and takes so long for excel in line .Range("A2").CopyFromRecordset rst
please help
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim WBCurrent As Workbook
Dim WS As Worksheet
'Change ScreenUpdating, Calculation, EnableEvents, ....
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
ActiveSheet.DisplayPageBreaks = False
Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ActiveWorkbook.FullName & ";" & _
"Extended Properties=""Excel 12.0;HDR=Yes;IMEX=0;Readonly=False"";"
.Open
End With
Set WBCurrent = ActiveWorkbook
WBCurrent.Worksheets("SAP1").Rows("2:100000").Delete
'mold_code = "002073-00"
strSQL = "SELECT [All$A1:L].[mold code], [All$A1:L].row, [All$A1:L].date2, [All$A1:L].[machine code], " _
& "(SELECT top 1 temp.[date2] FROM [All$A1:L] AS temp " _
& "WHERE temp.[machine code] = [All$A1:L].[machine code] AND temp.row > [All$A1:L].row " _
& "ORDER BY temp.row ) AS PreviousValue " _
& "FROM [All$A1:L]; "
Set rst = New ADODB.Recordset
rst.Open strSQL, cnn, adOpenStatic, adLockOptimistic
Set WS = WBCurrent.Worksheets("SAP1")
With WS
.Cells(1, 1) = "Machine Code"
.Cells(1, 2) = "Last Plan"
.Cells(1, 3) = "Mold Code"
.Range("A2").CopyFromRecordset rst
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlAutomatic
End With
Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.
If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.
Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
Bookmarks