Brief introduction: I'm pretty comfortable with programming in other languages, but am 100% new to VBA and Access so I welcome all comments.
I want to be able to plug in my camera and drag a picture from the camera (DCIM folder) into a form and have access move the file to the images folder, rename it according to the names on the form, store the relative path in the form, and show the picture. I am making a directory while learning how to use access.
Right now I am doing a more basic version where I put the file in the correct 'images' location and then drag it into the hyperlink text field. The program then, "_AfterUpdate() " renames the picture according to the form. The Form (and picture) then update according to the link. My problem is that "Picture_Link_A fterUpdate()" seems to be called before a link is created in the table. Is this a good way to go about this? Is there a better way? What do you suggest? Thank you!
Here's my code:
I want to be able to plug in my camera and drag a picture from the camera (DCIM folder) into a form and have access move the file to the images folder, rename it according to the names on the form, store the relative path in the form, and show the picture. I am making a directory while learning how to use access.
Right now I am doing a more basic version where I put the file in the correct 'images' location and then drag it into the hyperlink text field. The program then, "_AfterUpdate() " renames the picture according to the form. The Form (and picture) then update according to the link. My problem is that "Picture_Link_A fterUpdate()" seems to be called before a link is created in the table. Is this a good way to go about this? Is there a better way? What do you suggest? Thank you!
Here's my code:
Code:
Option Compare Database
Private Sub Picture_Link_AfterUpdate()
Dim oldPath As String, newPath As String, fileName As String
oldPath = GetFullImagePath
fileName = Me!Last & "_" & Me!First & ".jpg"
newPath = GetImagePath & fileName
If oldPath <> "" Then
Name oldPath As newPath
Me!PicturePath = "#\" & fileName
End If
End Sub
Private Sub Form_Current()
Image.Picture = GetFullImagePath
End Sub
Private Function GetFullImagePath() As String
Dim ImagePath As String
ImagePath = ""
If IsNull(Me!PicturePath) Then
Else
ImagePath = GetImagePath & GetFileName(Me!PicturePath)
If Len([PicturePath]) > 0 And Len(Dir(ImagePath)) > 0 Then
Else
ImagePath = ""
End If
End If
GetFullImagePath = ImagePath
End Function
Private Function GetImagePath() As String
GetImagePath = GetDBPath & "pictures\"
End Function
Private Function GetDBPath() As String
GetDBPath = CurrentProject.path & "\"
End Function
Private Function GetFileName(path As String) As String
Dim StartPos As Long
Dim StrLen As Long
StartPos = InStrRev(path, "\") + 1 '+1 is to not include the slash
StrLen = InStrRev(path, "#") - StartPos 'A link will end in a #
GetFileName = Mid(path, StartPos, StrLen)
End Function
Comment