View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
PatK PatK is offline
external usenet poster
 
Posts: 96
Default Referencing Database Fields

Ok...I did give that a shot:

Set tbk = ThisWorkbook.Application

but I get a type mismatch on the statement. Here is how tbk is dim'd:

Dim tbk As Workbook

I appreciate your help!!!! I have re-entered the code, as it is now:



Sub GetAppCIData()

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strWhere As String
Dim strFields As String
Dim strFieldin As String
Dim strTablein As String
Dim strSQL As String
Dim i As Integer
Dim tbk As Workbook

Set tbk = ThisWorkbook.Application


ClearForm
Set con = New ADODB.Connection
con.Open "Driver={SQL Server};Server=GVS00534\i06,2048;Database=Apate_Pr o;"

strTablein = "dbo.hpsc_application"

strFieldin = "HP_APP_PRTFL_ID, "
strFieldin = strFieldin & "solution_ID, "
strFieldin = strFieldin & "Solution_Alias, "
strFieldin = strFieldin & "Criticality, "
strFieldin = strFieldin & "Short_Description, "
strFieldin = strFieldin & "Lifecycle_Stage_Name, "
strFieldin = strFieldin & "Support_Owner_L2, "
strFieldin = strFieldin & "Support_Owner_L3, "
strFieldin = strFieldin & "SUPPORT_CONTACT, "
strFieldin = strFieldin & "Support_Portfolio_Contact, "
strFieldin = strFieldin & "Planned_Obs_Date, "
strFieldin = strFieldin & "HP_CI_OWN_ASGN_GRP_NM, "
strFieldin = strFieldin & "HP_IT_ASSET_OWN_ORG_HIER1_TX, "
strFieldin = strFieldin & "HP_SUPP_OWN_ORG_HIER1_TX, "
strFieldin = strFieldin & "date_of_last_record_update"

strWhere = "HP_APP_PRTFL_ID = '" & Range("EPRID") & "'"
Debug.Print "strWhe " & strWhere
strSQL = "SELECT " & strFieldin & " FROM " & strTablein & " WHERE " & strWhere
Debug.Print "strSQL: " & strSQL

Set rs = con.Execute(strSQL, , 1)
'Debug.Print "Lifecycle:" & rs.Fields("Lifecycle_Stage_Name").Value ' <---
Oddity starts here
'Debug.Print "L2:" & rs.Fields("Support_Owner_L2").Value ' <--- Oddity
starts here
'Debug.Print "L3:" & rs.Fields("Support_Owner_L3").Value ' <--- Oddity
starts here
'Debug.Print "Contact:" & rs.Fields("SUPPORT_CONTACT").Value ' <--- Oddity
starts here
With rs
tbk.Range("Application_Alias") = .Fields("Solution_Alias").Value 'works
fine
tbk.Range("Asset_Owner_Hierarchy") =
..Fields("HP_IT_ASSET_OWN_ORG_HIER1_TX").Value 'works fine from here on down
tbk.Range("Support_Owner_Hierarchy") =
..Fields("HP_SUPP_OWN_ORG_HIER1_TX").Value 'ok
tbk.Range("Criticality") = .Fields("Criticality").Value 'ok
tbk.Range("Solution_ID") = .Fields("solution_ID").Value 'ok
tbk.Range("L2_Support") = .Fields("Support_Owner_L2").Value ' does not
work without debug
tbk.Range("L3_Support") = .Fields("Support_Owner_L3").Value ' does not
work without debug
tbk.Range("Lifecycle") = .Fields("Lifecycle_Stage_Name").Value ' does
not work without debug
tbk.Range("Support_Contact") = .Fields("SUPPORT_CONTACT").Value ' does
not work without debug
tbk.Range("Record_Last_Updated") =
..Fields("date_of_last_record_update").Value 'ok
If .Fields("Planned_Obs_Date").Value < Null Then
tbk.Range("Obsolete") = .Fields("Planned_Obs_Date").Value ' ok
Else
tbk.Range("Obsolete") = "No Plan" 'ok
End If
If .Fields("HP_CI_OWN_ASGN_GRP_NM").Value < "" Then
tbk.Range("CI_Owner_AG") = .Fields("HP_CI_OWN_ASGN_GRP_NM").Value 'ok
Else
tbk.Range("CI_Owner_AG") = "Missing" 'ok
End If

End With

rs.Close
con.Close
Set rs = Nothing
Set con = Nothing

End Sub