정보를 검색하기 위해 다음을 시도했습니다. 엑셀 파일에 액세스 데이터베이스에서 :엑셀에서 열을 확인하여 vba를 사용하여 엑셀에서 데이터를 가져 오는 방법
Sub ddd()
Const dbloc As String = "C:\Users\mysystem1\Downloads\Database11.accdb"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim xlbook As Workbook
Dim xlsheet As Worksheet
Dim a As Long
Dim SQL As String
Set xlbook = ActiveWorkbook
Set xlsheet = xlbook.Worksheets(1)
xlsheet.Range("A5:Z100000").ClearContents
Application.StatusBar = "Connecting to external database..."
Set db = OpenDatabase(dbloc)
SQL = "SELECT Material_ID "
SQL = SQL & "FROM Sheet1"
'Sheet1 is the the access tablename
'SQL = SQL & "WHERE Material IN (500017,500024,500029)"
' i want to update the where condition above to a column in the excel wb itself
Set rs = db.OpenRecordset(SQL, dbOpenSnapshot)
If rs.RecordCount = 0 Then
MsgBox "No data retrieved from database", vbInformation + vbOKOnly, "No Data"
GoTo SubExit
Else
rs.MoveLast
recCount = rs.RecordCount
rs.MoveFirst
End If
xlsheet.Range("C5").CopyFromRecordset rs
End Sub
나는 엑셀 WB에서 열을 기준으로 결과를 반환하는 내 SQL 쿼리에 WHERE 조건을 업데이트 할. 하지만 올바른 구문을 얻지 못하고 있습니다.
도와주세요.
감사를 할 수있는 올바른 구문 나를 도울 수 이것은 잘 작동 상태가 엑셀 –