joshirohany
Registered User.
- Local time
- Today, 02:33
- Joined
- Apr 3, 2019
- Messages
- 33
Dear Experts,
I would like to thank in Advance for your help. I am new to Access as we as VBA / Macro.
I have a DB, where if there are three fields "Student Code, PPLINK, Attachments.
i have a code which helps me to auto insert Images of Student in Attachments.
Where Student Code is unique and PPLINK is the Path of the folder where their photo's are saved. after running the code, it insert attachments based on the PPLINK's path.
Code i have shared below.
Sub Test()
Dim cdb As DAO.Database, rstMain As DAO.Recordset, rstAttach As DAO.Recordset2, _
fldAttach As DAO.Field2
Set cdb = CurrentDb
Set rstMain = cdb.OpenRecordset("SELECT PPLink, Attachment FROM StudentDetails", dbOpenDynaset)
Do Until rstMain.EOF
rstMain.Edit
Set rstAttach = rstMain("Attachment").Value
rstAttach.AddNew
Set fldAttach = rstAttach.Fields("FileData")
fldAttach.LoadFromFile rstMain("PPLink").Value
rstAttach.Update
rstAttach.Close
Set rstAttach = Nothing
rstMain.Update
rstMain.MoveNext
Loop
rstMain.Close
Set rstMain = Nothing
Set cdb = Nothing
End Sub
My area of pain are mentioned below.
a. For Example :-
Student Code PPLINK Attachments
1001 D:\Photos\1001.jpg
1002 D:\Photos\1002.jpg
1003 D:\Photos\1003.jpg
Lets say if 1002's photo is not present in the folder then i am getting error in Yellow "rstAttach.Update". as well as its not going to next code to attaching the attachments.
b. Also i cant give a command button since its say's its not public.
Requesting Experts to help me on the same.
Thanking once again
I would like to thank in Advance for your help. I am new to Access as we as VBA / Macro.
I have a DB, where if there are three fields "Student Code, PPLINK, Attachments.
i have a code which helps me to auto insert Images of Student in Attachments.
Where Student Code is unique and PPLINK is the Path of the folder where their photo's are saved. after running the code, it insert attachments based on the PPLINK's path.
Code i have shared below.
Sub Test()
Dim cdb As DAO.Database, rstMain As DAO.Recordset, rstAttach As DAO.Recordset2, _
fldAttach As DAO.Field2
Set cdb = CurrentDb
Set rstMain = cdb.OpenRecordset("SELECT PPLink, Attachment FROM StudentDetails", dbOpenDynaset)
Do Until rstMain.EOF
rstMain.Edit
Set rstAttach = rstMain("Attachment").Value
rstAttach.AddNew
Set fldAttach = rstAttach.Fields("FileData")
fldAttach.LoadFromFile rstMain("PPLink").Value
rstAttach.Update
rstAttach.Close
Set rstAttach = Nothing
rstMain.Update
rstMain.MoveNext
Loop
rstMain.Close
Set rstMain = Nothing
Set cdb = Nothing
End Sub
My area of pain are mentioned below.
a. For Example :-
Student Code PPLINK Attachments
1001 D:\Photos\1001.jpg
1002 D:\Photos\1002.jpg
1003 D:\Photos\1003.jpg
Lets say if 1002's photo is not present in the folder then i am getting error in Yellow "rstAttach.Update". as well as its not going to next code to attaching the attachments.
b. Also i cant give a command button since its say's its not public.
Requesting Experts to help me on the same.
Thanking once again