因此,我们有一个简单的查询,我们可以将8位数字的列格式化为CRN值,这很好,但是如果将数字放在Excel工作表中并尝试在VBA中运行循环查询,我们不会得到任何结果。
我做错了什么或错过了什么?
Dim DB_CONNECTION As ADODB.Connection
Dim DB_RECORDSET As ADODB.Recordset
Dim CELLADDRESS As Variant
Dim CRN As Variant
Dim ANSWER As String
Dim SQL_STRING As String
Set DB_CONNECTION = New ADODB.Connection
Set DB_RECORDSET = New ADODB.Recordset
DB_CONNECTION.ConnectionString = "Driver={Oracle in OraClient18Home1_32bit}; Dbq=XXXXXX; Uid=XXXXX; Pwd=XXXXXX;QTO=F;"
DB_CONNECTION.Open
Sheets("Data").Activate
Range("A6").Select
Do Until IsEmpty(ActiveCell)
CELLADDRESS = ActiveCell.Address
CRN = ActiveCell.Value
SQL_STRING = ""
SQL_STRING = SQL_STRING + " SELECT CUSTIMA.BCUSTCLS.U##CLASS_CODEC"
SQL_STRING = SQL_STRING + " FROM CUSTIMA.BCUSTCLS"
SQL_STRING = SQL_STRING + " WHERE CUSTIMA.BCUSTCLS.U##CUST_REF = 'CRN'"
SQL_STRING = SQL_STRING + " AND CUSTIMA.BCUSTCLS.U##CLASS_CODEC = 'DO' "
DB_RECORDSET.Open SQL_STRING, DB_CONNECTION
Sheets("Data").Range(CELLADDRESS).Offset(0, 2).CopyFromRecordset DB_RECORDSET
DB_RECORDSET.Close
ActiveCell.Offset(1, 0).Select
Loop
End Sub
1条答案
按热度按时间hivapdat1#
类似这样的方法应该可以奏效: