heatherb0123
Technical User
I'm trying to create local Access tables for data linked via ODBC from Sybase (I know the SQL code connecting to Sybase is correct. I tested it in a diff module and it returns the exact # of records). I would like to create tables within access, but I can't get the code to work. Any help would be appreciated. Below is my code. When I step through the code, I notice that when it gets to "Do While Not rsSQL.EOF" it skips to the end of the code as if the recordset is already at end the of file???
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Function GetHiNet_Data()
'Define and open connection to SQL
Dim conSQL As ADODB.Connection
Set conSQL = New ADODB.Connection
conSQL.Open "DRIVER={SYBASE ASE ODBC Driver};NA=GPSURS,
3000;UID=bssapp;PWD=bssapp;"
'Define SQL command
Dim cmdSQL As ADODB.Command
Set cmdSQL = New ADODB.Command
cmdSQL.ActiveConnection = conSQL
cmdSQL.CommandText = "SELECT trp_holdrefN.acid, pr_account.acnomajor,
pr_account.acnominor, trp_holdrefN.smsecid, pr_secxref.sxvalue, trp_holdrefN.
quantity, trp_holdrefN.cost_base, trp_holdrefN.cost_local, trp_amtbaseN.
lcl_amort_cost " _
& "FROM pr_account INNER JOIN trp_holdrefN ON pr_account.acid = trp_holdrefN.
acid INNER JOIN pr_secxref ON trp_holdrefN.smsecid = pr_secxref.smsecid INNER
JOIN trp_amtbaseN ON trp_holdrefN.effdate = trp_amtbaseN.effdate AND
trp_holdrefN.smsecid = trp_amtbaseN.smsecid AND trp_holdrefN.acid =
trp_amtbaseN.acid WHERE pr_secxref.sxitm = 2 And pr_secxref.sxenddate > '" &
rptdte & "' And trp_holdrefN.effdate ='" & rptdte & "' " _
& "GROUP BY trp_holdrefN.acid, pr_account.acnomajor, pr_account.acnominor,
trp_holdrefN.smsecid, pr_secxref.sxvalue, trp_holdrefN.quantity, trp_holdrefN.
cost_base, trp_holdrefN.cost_local, trp_amtbaseN.lcl_amort_cost " _
& "HAVING trp_holdrefN.acid = 7929 Or trp_holdrefN.acid = 7939 Or
trp_holdrefN.acid = 7947 Or trp_holdrefN.acid = 7928 Or trp_holdrefN.acid =
7905 Or trp_holdrefN.acid = 7932 Or trp_holdrefN.acid = 7936 Or trp_holdrefN.
acid = 7930 Or trp_holdrefN.acid = 8313 Or trp_holdrefN.acid = 8315 Or
trp_holdrefN.acid = 9558 " _
& "ORDER BY trp_holdrefN.acid, trp_holdrefN.smsecid"
cmdSQL.CommandType = adCmdText
'Define and open recordset returned from SQL
Dim rsSQL As ADODB.Recordset
Set rsSQL = New ADODB.Recordset
rsSQL.Open cmdSQL
'Define connection to the local Access Database
Dim conLocal As ADODB.Connection
Set conLocal = CurrentProject.Connection
'Define Local command 1 and execute it - clear down tblHiNet_Data
Dim cmdL1 As ADODB.Command
Set cmdL1 = New ADODB.Command
cmdL1.ActiveConnection = conLocal
cmdL1.CommandText = "Delete from tblHiNet_Data"
cmdL1.CommandType = adCmdText
cmdL1.Execute
'Define Local command 2 and execute it - create empty local recordset
Dim cmdL2 As ADODB.Command
Set cmdL2 = New ADODB.Command
cmdL2.ActiveConnection = conLocal
cmdL2.CommandText = "select * from tblHiNet_Data"
Dim rsL As ADODB.Recordset
Set rsL = New ADODB.Recordset
rsL.Open cmdL2, , adOpenDynamic, adLockOptimistic
' Loop around the SQL recordset to populate the local recordset and update
tblHiNet_Data
Dim intCount As Integer
Do While Not rsSQL.EOF 'Recordset is at end of file???
rsL.AddNew
For intCount = 0 To 2000
rsL.Fields(intCount) = rsSQL.Fields(intCount)
Next intCount
rsL.Update
rsSQL.MoveNext
Loop
'Clean up
Set conSQL = Nothing
Set conLocal = Nothing
Set cmdSQL = Nothing
Set cmdL1 = Nothing
Set cmdL2 = Nothing
Set rsSQL = Nothing
Set rsL = Nothing
End Function
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Function GetHiNet_Data()
'Define and open connection to SQL
Dim conSQL As ADODB.Connection
Set conSQL = New ADODB.Connection
conSQL.Open "DRIVER={SYBASE ASE ODBC Driver};NA=GPSURS,
3000;UID=bssapp;PWD=bssapp;"
'Define SQL command
Dim cmdSQL As ADODB.Command
Set cmdSQL = New ADODB.Command
cmdSQL.ActiveConnection = conSQL
cmdSQL.CommandText = "SELECT trp_holdrefN.acid, pr_account.acnomajor,
pr_account.acnominor, trp_holdrefN.smsecid, pr_secxref.sxvalue, trp_holdrefN.
quantity, trp_holdrefN.cost_base, trp_holdrefN.cost_local, trp_amtbaseN.
lcl_amort_cost " _
& "FROM pr_account INNER JOIN trp_holdrefN ON pr_account.acid = trp_holdrefN.
acid INNER JOIN pr_secxref ON trp_holdrefN.smsecid = pr_secxref.smsecid INNER
JOIN trp_amtbaseN ON trp_holdrefN.effdate = trp_amtbaseN.effdate AND
trp_holdrefN.smsecid = trp_amtbaseN.smsecid AND trp_holdrefN.acid =
trp_amtbaseN.acid WHERE pr_secxref.sxitm = 2 And pr_secxref.sxenddate > '" &
rptdte & "' And trp_holdrefN.effdate ='" & rptdte & "' " _
& "GROUP BY trp_holdrefN.acid, pr_account.acnomajor, pr_account.acnominor,
trp_holdrefN.smsecid, pr_secxref.sxvalue, trp_holdrefN.quantity, trp_holdrefN.
cost_base, trp_holdrefN.cost_local, trp_amtbaseN.lcl_amort_cost " _
& "HAVING trp_holdrefN.acid = 7929 Or trp_holdrefN.acid = 7939 Or
trp_holdrefN.acid = 7947 Or trp_holdrefN.acid = 7928 Or trp_holdrefN.acid =
7905 Or trp_holdrefN.acid = 7932 Or trp_holdrefN.acid = 7936 Or trp_holdrefN.
acid = 7930 Or trp_holdrefN.acid = 8313 Or trp_holdrefN.acid = 8315 Or
trp_holdrefN.acid = 9558 " _
& "ORDER BY trp_holdrefN.acid, trp_holdrefN.smsecid"
cmdSQL.CommandType = adCmdText
'Define and open recordset returned from SQL
Dim rsSQL As ADODB.Recordset
Set rsSQL = New ADODB.Recordset
rsSQL.Open cmdSQL
'Define connection to the local Access Database
Dim conLocal As ADODB.Connection
Set conLocal = CurrentProject.Connection
'Define Local command 1 and execute it - clear down tblHiNet_Data
Dim cmdL1 As ADODB.Command
Set cmdL1 = New ADODB.Command
cmdL1.ActiveConnection = conLocal
cmdL1.CommandText = "Delete from tblHiNet_Data"
cmdL1.CommandType = adCmdText
cmdL1.Execute
'Define Local command 2 and execute it - create empty local recordset
Dim cmdL2 As ADODB.Command
Set cmdL2 = New ADODB.Command
cmdL2.ActiveConnection = conLocal
cmdL2.CommandText = "select * from tblHiNet_Data"
Dim rsL As ADODB.Recordset
Set rsL = New ADODB.Recordset
rsL.Open cmdL2, , adOpenDynamic, adLockOptimistic
' Loop around the SQL recordset to populate the local recordset and update
tblHiNet_Data
Dim intCount As Integer
Do While Not rsSQL.EOF 'Recordset is at end of file???
rsL.AddNew
For intCount = 0 To 2000
rsL.Fields(intCount) = rsSQL.Fields(intCount)
Next intCount
rsL.Update
rsSQL.MoveNext
Loop
'Clean up
Set conSQL = Nothing
Set conLocal = Nothing
Set cmdSQL = Nothing
Set cmdL1 = Nothing
Set cmdL2 = Nothing
Set rsSQL = Nothing
Set rsL = Nothing
End Function