2016-10-27 2 views
0
Private Sub Command203_Click() 'DOWNLOAD ALL ANNEXURES AT ONCE 
Dim rs As DAO.Recordset 
Set rs = CurrentDb.OpenRecordset("SELECT IDRT FROM RT WHERE STRT=ME.IDMN") 
'Check to see if the recordset actually contains rows 
If Not (rs.EOF And rs.BOF) Then 
    rs.MoveFirst 'Unnecessary in this case, but still a good habit 
    Do Until rs.EOF = True 
    Picker = "D:\1\" 'Destination path 
    path = [Forms]![1userselect]![APPENDIX] 'Get source file path 
    strFileName = Dir(path & IDRT & ".*") 
    Ext = Right(strFileName, Len(strFileName) - InStrRev(strFileName, ".")) 
    Dot = "." 
    S = path & IDRT & Dot & Ext 
    D = Picker & IDRT & Dot & Ext 
    FileCopy S, D 
     'Move to the next record. Don't ever forget to do this. 
     rs.MoveNext 
    Loop 
Else 
    MsgBox "There are no annexures in this report." 
End If 
MsgBox "Finished downloadinng annexures." 
rs.Close 'Close the recordset 
Set rs = Nothing 'Clean up 
End Sub 

나는 감사인이며 VBA에 대한 지식이 매우 부족합니다. 위의 코드는 다른 사람들의 사본 붙여 넣기입니다. 배우는 데 도움이 될 수있는 변경 사항에 대한 의견이 추가되면 도움이 될 것입니다. 작업 : 레코드 집합을 반복하고 내 양식 (Me.IDMN)에 STRT가있는 레코드의 IDRT (서버 폴더의 파일 이름)를 가져옵니다. 문제점 : 쿼리 작성기에서 SQL select 문을 테스트 할 때 IDRT가 올바르게 필터링됩니다. copyfile 메커니즘은 또한 별도로 테스트되고 잘 작동합니다 (IDRT를 텍스트 상자에 직접 입력 한 경우).루프 및 복사 파일이 액세스에 통합 됨 2016 vba

답변

0

SQL을 올바르게 작성하는 것처럼 보이지 않습니다.

시도 :

Set rs = CurrentDb.OpenRecordset("SELECT IDRT FROM RT WHERE STRT=" & Me.IDMN) 

IDMN 숫자 인 경우.

또는

Set rs = CurrentDb.OpenRecordset("SELECT IDRT FROM RT WHERE STRT='" & Me.IDMN & "'") 

텍스트

+0

감사합니다 팀,하지만 여전히 작동하지 않습니다. IDRT와 IDMN은 모두 숫자이지만 소스 파일의 경로는 실제로 다음과 같습니다. \\ 192.168 ...... 이것이 문제가 될 수 있습니까? –

+0

치수를 정의하지 않은 한 가지 문제점을 발견했습니다. 이제 나는 그것들을 정의했다. –

+0

하지만 여전히 코드가 작동하지 않습니다. –

0

다음 코드는 지금 작동하고 있는지 :

Private Sub Command6_Click() 

Dim rs As DAO.Recordset 
Dim sourcePATH As String 
Dim destinPATH As String 
Dim StrSQL As String 
Dim strFileName As String 
Dim exten As String 
Dim source As String 
Dim destin As String 

sourcePATH = "D:\1\" 
destinPATH = "D:\2\" 
StrSQL = "SELECT RT.STRT, RT.IDRT " & _ 
      "FROM RT " & _ 
      "WHERE (((RT.STRT) = " & Me.Text2 & "))" 

Set rs = CurrentDb.OpenRecordset(StrSQL) 
rs.MoveFirst 
Do Until rs.EOF 
strFileName = Dir(sourcePATH & rs!IDRT & ".*") 
If Len(strFileName) = 0 Then 
rs.MoveNext 
Else 
exten = Right(strFileName, Len(strFileName) - InStrRev(strFileName, ".")) 
source = sourcePATH & rs!IDRT & "." & exten 
destin = destinPATH & rs!IDRT & "." & exten 
FileCopy source, destin 
rs.MoveNext 
End If 
Loop 
rs.Close 
Set rs = Nothing 
Set db = Nothing 
End Sub