2
나는 계속 루프를 반복하고있다 (나는 믿는다). 코드를 실행하면 MsgBox 프롬프트가 나타나고 확인을 클릭하면 프로그램이 실행되고 실행되고 끝나지 않습니다. 처음에는 파일 오류에 대한 연결이라고 가정했지만 ADO가 파일에 연결하려고하면 오류가 발생합니다. 맞습니까? 파일 크기가 커서 70ish 행만입니다. 나는 MsgBox가 설정된 방식대로 루프를 통해 모든 반복을 클릭 할 때 확인 메시지를 표시해야하지만 다른 MsgBox는 수신하지 않습니다. 제안?연속 루프 ADO VBA 액세스 2010
' The following section reads from the elec_copy field's hyperlink
' It scans the Excel file for items it needs to include into the table
' It enters those cells into the TABLE 'items_needed_table'
'
' Selects row by row, and if the item has been marked TRUE, inserts
' That row into the TABLE 'items_needed_table'
' Open a connection to Excel
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & elec_copy.Value & ";" & _
"Extended Properties=""Excel 12.0 Macro;HDR=Yes;"";"
' Decalre a RecordSet Object
Set objRecordSet = CreateObject("ADODB.Recordset")
' Grab all Rows in the Plain_VDR Sheet where 'needed' column == TRUE
objRecordset.Open "SELECT line_no,desc,weeks FROM [Plain_VDR$] WHERE needed = TRUE", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
' Write the information pulled, into the TABLE 'items_needed_table' in Access Database
Do Until objRecordset.EOF
MsgBox("" & qd.Parameters("p2"))
Set qd = data_base.CreateQueryDef("")
qd.sql = "INSERT INTO items_needed_table(pr_no, line_no, desc, weeks) " & _
"Values([p1],[p2],[p3],[p4])"
qd.Parameters("p1").Value = pr_num.Value
qd.Parameters("p2").Value = objRecorset.Fields.Item("line_no")
qd.Parameters("p3").Value = objRecordset.Fields.Item("desc")
qd.Parameters("p4").Value = objRecordset.Fields.Item("weeks")
qd.Execute
objRecordset.MoveNext
Loop
' Close Database connection
data_base.Close
도움을 주셔서 감사합니다. Nathan
위시 'On Error Resume Next'와 'Option Explicit'모두에 주목하기 때문에 +2 할 수 있습니다. –
@Remou 당신은 요즘 내 영웅입니다. 감사! – nathansizemore