I have a program with all employees; each employee has a specific file of attachments. When I click on a specific employee name from the master list, a form opens with their file attachments.
I created a button that should open a Query then loop through to copy each employee attachment to another location.
The loop transfers all employee files. It will not let me filter the query to the specific employee open in my form when I try to apply the employee id (empl_id).
I tried adding the empl_id filter directly to the query itself. It works without the filter, but breaks when I add the filter parameter.
I tried prompting the user from VBA to type in the empl_id, so that it will filter the correct employee.
Currently, I tried using docmd.applyfilter in my VBA after the query is open.
Sub btnTransferAllPublic_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim emplid As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("qry_Attachments_All_Public_Ind_Transfer", dbOpenDynaset, dbSeeChanges)
Set emplid = rst!empl_id & Forms!frm_Employee_All!empl_id
DoCmd.ApplyFilter , emplid
Do Until rst.EOF
Debug.Print rst!empl_id & " | " & rst![ATTID]
'Beginning of to do
Const SavePath = "C:\Users\Public\Desktop\HRP_TRANSFER\"
Dim sourcefile As String
Dim destfile As String
Dim ext As String
On Error Resume Next
MkDir "C:\Users\Public\Desktop\HRP_TRANSFER\"
On Error GoTo 0
sourcefile = rst!ATTACHLINK
destfile = "C:\Users\Public\Desktop\HRP_TRANSFER\"
ext = rst!attachfile
FileCopy sourcefile, (destfile & ext)
' End of to do
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
'This is a message that tells user when all files have been transferred successfully
MsgBox "Transfer Complete"
End Sub