TheEntertainer
MIS
I've recorded and mangled the following VBA code and it works fine in Excel 97 querying a Oracle 7 database:
Sub recon()
Dim StartDate
Dim EndDate
Dim UserID As String
Dim PassW As String
Dim sACCOUNT As String
sACCOUNT = InputBox("Enter Account"
sBNKCOD = InputBox("Enter Bank Code"
UserID = InputBox("Enter User ID"
PassW = InputBox("Enter Password"
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={Microsoft ODBC for Oracle};UID=" & UserID & ";PWD=" & PassW & ";SERVER=PMIS;", _
Destination:=Range("A1"
)
'With ActiveSheet.QueryTables.Add(Connection:= _
'"ODBC;DRIVER={Microsoft ODBC for Oracle};UID=" & UserID & ";PWD=" & PassW & ";SERVER=PMIS;", _
Destination:=Range("A1"
)
.Sql = Array( _
"SELECT" & Chr(13) & "" & Chr(10) & " CLAIM.""ACC_NUM"", CLAIM.""CLM_NUM"", CLAIM.""OCC_DTE""," & Chr(13) & "" & Chr(10) & " PAYMENT.""BNK_COD"", PAYMENT.""PMT_TYP"", PAYMENT.""CHK_NUM"", PAYMENT.""ISS_DTE"" , PAYMENT.""PAID"", null " & Chr(13) & "" & Chr(10) & "FROM" & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""CLAIM"" CLA" _
, _
"IM," & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""PAYMENT"" PAYMENT" & Chr(13) & "" & Chr(10) & "WHERE" & Chr(13) & "" & Chr(10) & " CLAIM.""UNQ_ID"" = PAYMENT.""UNQ_ID"" AND" & Chr(13) & "" & Chr(10) & " CLAIM.""ACC_NUM"" ='" & sACCOUNT & "' AND" & Chr(13) & "" & Chr(10) & " PAYMENT.""BNK_COD"" = '" & sBNKCOD & "' " & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "union all" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "SELECT" & Chr(13) & "" & Chr(10) & " null ,null ,to_dat" _
, _
"e(null) ," & Chr(13) & "" & Chr(10) & " BANK.""BNK_COD"",BANKTRAN.""TRN_TYP"", to_number(null) , BANKTRAN.""TRN_DTE"" , BANKTRAN.""TRN_AMT"", BANKTRAN.""COM_TXT""" & Chr(13) & "" & Chr(10) & "FROM" & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""BANK"" BANK," & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""BANKTRAN"" BANKTRAN" & Chr(13) & "" & Chr(10) & "" _
, _
"WHERE" & Chr(13) & "" & Chr(10) & " BANK.""UNQ_ID"" = BANKTRAN.""UNQ_ID"" AND" & Chr(13) & "" & Chr(10) & " BANK.""BNK_COD"" = '" & sBNKCOD & "'" _
)
Dim text1 As String
text1 = ActiveSheet.QueryTables(1).Sql
MsgBox text1
.FieldNames = True
.RefreshStyle = xlOverwriteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Name = "Reconciliation"
.Refresh BackgroundQuery = False
End With
End Sub
However if I run it in Excel 2000 it generates an error:
Run-Time Error 1004 - General ODBC Error. Debugging identifies the line:
.Refresh BackgroundQuery = False
I know that the .sql line changes in Excel 2000 to .commandtext, but even changing this doesn't make a difference. I've tried recording directly in 2000 and if you try refreshing by right click on a cell within the range generated by the query, it refreshes, but if you try to run the code generated it,errors at the same line (although slightly different syntax in 2000)
.Refresh BackgroundQuery:=False
Any ideas would be appreciated.
![[nosmiley] [nosmiley] [nosmiley]](/data/assets/smilies/nosmiley.gif)
Sub recon()
Dim StartDate
Dim EndDate
Dim UserID As String
Dim PassW As String
Dim sACCOUNT As String
sACCOUNT = InputBox("Enter Account"
sBNKCOD = InputBox("Enter Bank Code"
UserID = InputBox("Enter User ID"
PassW = InputBox("Enter Password"
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={Microsoft ODBC for Oracle};UID=" & UserID & ";PWD=" & PassW & ";SERVER=PMIS;", _
Destination:=Range("A1"
'With ActiveSheet.QueryTables.Add(Connection:= _
'"ODBC;DRIVER={Microsoft ODBC for Oracle};UID=" & UserID & ";PWD=" & PassW & ";SERVER=PMIS;", _
Destination:=Range("A1"
.Sql = Array( _
"SELECT" & Chr(13) & "" & Chr(10) & " CLAIM.""ACC_NUM"", CLAIM.""CLM_NUM"", CLAIM.""OCC_DTE""," & Chr(13) & "" & Chr(10) & " PAYMENT.""BNK_COD"", PAYMENT.""PMT_TYP"", PAYMENT.""CHK_NUM"", PAYMENT.""ISS_DTE"" , PAYMENT.""PAID"", null " & Chr(13) & "" & Chr(10) & "FROM" & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""CLAIM"" CLA" _
, _
"IM," & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""PAYMENT"" PAYMENT" & Chr(13) & "" & Chr(10) & "WHERE" & Chr(13) & "" & Chr(10) & " CLAIM.""UNQ_ID"" = PAYMENT.""UNQ_ID"" AND" & Chr(13) & "" & Chr(10) & " CLAIM.""ACC_NUM"" ='" & sACCOUNT & "' AND" & Chr(13) & "" & Chr(10) & " PAYMENT.""BNK_COD"" = '" & sBNKCOD & "' " & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "union all" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "SELECT" & Chr(13) & "" & Chr(10) & " null ,null ,to_dat" _
, _
"e(null) ," & Chr(13) & "" & Chr(10) & " BANK.""BNK_COD"",BANKTRAN.""TRN_TYP"", to_number(null) , BANKTRAN.""TRN_DTE"" , BANKTRAN.""TRN_AMT"", BANKTRAN.""COM_TXT""" & Chr(13) & "" & Chr(10) & "FROM" & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""BANK"" BANK," & Chr(13) & "" & Chr(10) & " ""PYROWNER"".""BANKTRAN"" BANKTRAN" & Chr(13) & "" & Chr(10) & "" _
, _
"WHERE" & Chr(13) & "" & Chr(10) & " BANK.""UNQ_ID"" = BANKTRAN.""UNQ_ID"" AND" & Chr(13) & "" & Chr(10) & " BANK.""BNK_COD"" = '" & sBNKCOD & "'" _
)
Dim text1 As String
text1 = ActiveSheet.QueryTables(1).Sql
MsgBox text1
.FieldNames = True
.RefreshStyle = xlOverwriteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Name = "Reconciliation"
.Refresh BackgroundQuery = False
End With
End Sub
However if I run it in Excel 2000 it generates an error:
Run-Time Error 1004 - General ODBC Error. Debugging identifies the line:
.Refresh BackgroundQuery = False
I know that the .sql line changes in Excel 2000 to .commandtext, but even changing this doesn't make a difference. I've tried recording directly in 2000 and if you try refreshing by right click on a cell within the range generated by the query, it refreshes, but if you try to run the code generated it,errors at the same line (although slightly different syntax in 2000)
.Refresh BackgroundQuery:=False
Any ideas would be appreciated.
![[nosmiley] [nosmiley] [nosmiley]](/data/assets/smilies/nosmiley.gif)