0
VBA ListBox userform에 대한 SQL 연결/소스를 설정하는 데 어려움을 겪고 있습니다. 나는 올바른 SQL 테이블을 엑셀 시트 (아래의 코드에서)로 가져올 수 있었지만 지금까지의 모든 시도는리스트 박스의 소스와 동일한 데이터를로드하지 못했습니다. 아래의 코드는 내 동료에게 주어졌으며 db에 맞춰졌습니다.vba userform에 대한 sql 소스
Sub SQL_VBA()
Dim sConn As String
Dim oQt As QueryTable
Dim sSql As String
'defining the connection string
sConn = "ODBC;DSN=RISK_DB;UID=;PWD=;"
sConn = sConn & "WSID=;DATABASE=RISK_DB"
sSql = str_SQLText
Set oQt = Sheet1.QueryTables.Add(Connection:=sConn, Destination:=Sheet1.Range("A1"), Sql:=sSql)
With oQt
.Name = "Query from"
.FieldNames = True '' This returns the headers of the tables you need
.RowNumbers = False
.PreserveFormatting = True
.RefreshOnFileOpen = False '' Dont want to refresh file each time it opens
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=True
End With
End Sub
userforms의 데이터 소스로 SQL 테이블을로드하는 경험이 있습니까?