Access에서 콤보 상자 필드의 값을 가져 와서 Excel 워크 시트의 문자열 값을 출력하려고합니다. 몇 가지 솔루션/해킹 시도하고 445 오류가 계속.Access에서 콤보 상자 값을 Excel로 출력
콤보 박스는 회원 (예 : 게이 남성, 노령 인구, Trans *, 사람 색상, 원주민 그룹, 여성, 뉴 캐나다인 등)이 제공하는 커뮤니티 또는 인구의 드롭 다운 목록입니다. 선택된 (현재는 빈 레코드가 있습니다).
Sub OutputSub()
' Define a recordset for the Table I am using
Dim myConnection As ADODB.Connection
Set myConnection = CurrentProject.Connection
Dim myRecordset As New ADODB.Recordset
myRecordset.ActiveConnection = myConnection
myRecordset.Open "MemberList", , adOpenStatic, adLockOptimistic
' Open Excel and make a worksheet for me
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
' Make Excel visible through the Application object.
xlSheet.Application.Visible = True
' Variables for each of the values I will need
Dim memCom As Variant, memServ As Variant, memLangs As Variant, memTot As Variant
Dim memNum As Integer
memNum = 2
xlSheet.Application.Cells(1, 4).Value = "Services"
'This loops through each of the records in the Table MemberList
myRecordset.MoveFirst
Do Until myRecordset.EOF()
memCom = myRecordset.Fields("Communities Served")
' This next line causes a 1004 error, application or object defined error
xlSheet.Application.Cells(memNum, 4).Value = memCom
'Debug.Print memCom, memServ, memLangs
memNum = memNum + 1
myRecordset.MoveNext
Loop
' Cleanup open files/variables, just in case
myRecordset.Close
Set myRecordset = Nothing
Set myConnection = Nothing
End Sub
내 목표는 더 내가 Excel 파일로 DB를 보낸 경우 같은 값으로 엑셀 시트를 가지고있다 :
여기 내 코드입니다. VBA에서이 작업을 수행하려고합니다. 특정 형식으로 필요한 정보를 3 열 이전에 가지고 있기 때문에 (올바르게 작업 했으므로 잘라 냈습니다).
(한국어) StackExchange에서 콤보 상자의 값에 액세스하는 방법에 대한 정보가 거의없고 상자에 필드를 추가하는 방법에 대한 팁이 많이 있습니다. 나는 이것에 대한 약간의 멍청한 짓이며 여기에 오기 위해 일주일이 걸렸다. 그리고 지금 나의 DB를위한 결과물을 완성하기위한 진지한 도움을 요청하고있다.
감사 리즈
UPDATE : 런타임 오류 1004 : 주석으로 코드에서 언급 한 바와 같이 응용 프로그램 정의 또는 개체 정의 오류가 발생합니다.
업데이트 2 : Office Dev Center : https://social.msdn.microsoft.com/Forums/office/en-US/f5de518d-a2f0-41b8-bfd3-155052547ab5/export-of-combo-box-to-excel-with-values-access-2010?forum=accessdev에서이 파생 결과가 나왔지만 코드 스 니펫에 적용하는 방법을 잘 모르겠습니다. 나는 memName과 함께 필요한 정보를 출력하는 쿼리를 만들었지 만이 출력의 일부분을 만드는 방법에 대해서는 분실했습니다.
여기서 오류가 있습니까? xlSheet.Application.Cells (1, 4)를 사용할 수도 있습니다. CopyFromRecordset myRecordset –
해당 솔루션 (레코드 세트에서 복사)은 형식이 일치하지 않습니다. (현재 주 항목에서 오류가 발생한 위치를 추가하고 있습니다) – Liz
xlSheet.Cells (1, 4) .CopyFromRecordset myRecordset –