I could get the VBA to open the file without a query string and loop through the recordset 1 record at a time. I can't get a query string to work.
Every combination I've tried using a SQL query string produces Run Time Error 3421 - Data type conversion error. As you can see, I'm using a trial of just a single field. I have tried both a string field and numeric field.
Yesterday I searched through every posting I could find on MS ACCESS / DB2 and could not find an example with code provided.
Here is my VBA code with the different combinations I've tried:
Expand|Select|Wrap|Line Numbers
- Sub PassThroughLoop()
- Dim sSQL As String
- Dim rst As DAO.Recordset
- ' AS400 SQL
- ' sSQL = "SELECT BJDOCD FROM ID3SCVDTA.COVDTLP WHERE ID3SCVDTA.COVDTLP.BJDOCD='00CC157640'"
- sSQL = "SELECT ID3SCVDTA.COVDTLP.BJACSG FROM ID3SCVDTA.COVDTLP WHERE ID3SCVDTA.COVDTLP.BJACSG=1298677"
- ' MS Access SQL
- ' sSQL = "SELECT ID3SCVDTA_COVDTLP.BJDOCD FROM ID3SCVDTA_COVDTLP WHERE ID3SCVDTA_COVDTLP.BJDOCD ='00CC157640'"
- ' sSQL = "SELECT ID3SCVDTA_COVDTLP.BJACSG FROM ID3SCVDTA_COVDTLP WHERE ID3SCVDTA_COVDTLP.BJACSG=1298677;"
- 'MsgBox "sSQL string is: " & sSQL
- Set rst = CurrentDb.TableDefs("ID3SCVDTA_COVDTLP").OpenRecordset(sSQL)
- With rst
- .MoveFirst
- Do Until .EOF
- MsgBox "Policy " & rst!BJDOCD
- .MoveNext
- Loop
- End With
- rst.Close
- Set rst = Nothing
- End Sub