D
Dan Thorman
Hello all...
I wrote the following Macro to try to figure out how to use ADODB.Recordset.
Basically, I am grabbing a one row recordset, and i would like to assign the
values of that recordset to cells in my Excel worksheet based on the column
name. Unfortunately, I'm getting an error when I try to open the recordset
(the two assignments below the recordset were my attempts at figuring out if
i could assign a value based on either the position of the column or the name
of the column). If anybody could tell me what i'm doing wrong, that would be
outstanding.
Thanks in advance!
Sub test()
Dim DealID As Long
DealID = Range("Inputs!DealID")
sSql = "select (case when project_type_id in (2, 11) then 'Conversion' " &
vbCrLf
sSql = sSql & "when project_type_id in (3,7,9) then 'New Build'" & vbCrLf
sSql = sSql & "when project_type_id = 1 then 'Adaptive Re-Use'" & vbCrLf
sSql = sSql & "when project_type_id = 6 then 'Change of Ownership'" & vbCrLf
sSql = sSql & "when project_type_id in (5,8) then 'Re Up'" & vbCrLf
sSql = sSql & "when project_type_id is NULL then 'Data Not Found in ABCD'
end) Project_Type, " & vbCrLf
sSql = sSql & "deal_name as Deal_Name from abcd.deal where deal_id = " &
DealID
Dim objRS As ADODB.Recordset
Dim objField As ADODB.Fields
Set objRS = New ADODB.Recordset
objRS.Open sSql, ActDB, adOpenKeyset, adLockReadOnly, adCmdText
objRS.MoveFirst
Range("Inputs!ProjectType") = objRS.Fields(4).Value
Range("Inputs!DealName") = objRS.Fields("Deal_Name").Value
End Sub
I wrote the following Macro to try to figure out how to use ADODB.Recordset.
Basically, I am grabbing a one row recordset, and i would like to assign the
values of that recordset to cells in my Excel worksheet based on the column
name. Unfortunately, I'm getting an error when I try to open the recordset
(the two assignments below the recordset were my attempts at figuring out if
i could assign a value based on either the position of the column or the name
of the column). If anybody could tell me what i'm doing wrong, that would be
outstanding.
Thanks in advance!
Sub test()
Dim DealID As Long
DealID = Range("Inputs!DealID")
sSql = "select (case when project_type_id in (2, 11) then 'Conversion' " &
vbCrLf
sSql = sSql & "when project_type_id in (3,7,9) then 'New Build'" & vbCrLf
sSql = sSql & "when project_type_id = 1 then 'Adaptive Re-Use'" & vbCrLf
sSql = sSql & "when project_type_id = 6 then 'Change of Ownership'" & vbCrLf
sSql = sSql & "when project_type_id in (5,8) then 'Re Up'" & vbCrLf
sSql = sSql & "when project_type_id is NULL then 'Data Not Found in ABCD'
end) Project_Type, " & vbCrLf
sSql = sSql & "deal_name as Deal_Name from abcd.deal where deal_id = " &
DealID
Dim objRS As ADODB.Recordset
Dim objField As ADODB.Fields
Set objRS = New ADODB.Recordset
objRS.Open sSql, ActDB, adOpenKeyset, adLockReadOnly, adCmdText
objRS.MoveFirst
Range("Inputs!ProjectType") = objRS.Fields(4).Value
Range("Inputs!DealName") = objRS.Fields("Deal_Name").Value
End Sub