Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Linking a picture to a form record from network folder

Results 1 to 6 of 6
Share This Thread →
  1. #1
    randle is offline Registered User
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Linking a picture to a form record from network folder

    Hi


    I have a form which shows individual records for users and I want to link photos for each record from a network folder rather than embedding them in the database as good practice suggests.


    I've been using the database expample from Displaying Images in a Form | Database Solutions for Microsoft Access | databasedev.co.uk as a guide and have got it doing all I want other than actually displaying the picture in the picture control.


    Form name: tblPerson
    Picture path text field: txtImageName
    Image Control: ImageFrame
    Command button: cmdAddImage
    Command button: cmdDeleteImage


    Code:
    The Event Procedure is assigned to the On Click event and looks like: 
    
    Private Sub cmdAddImage_Click()
    On Error GoTo cmdAddImage_Err
    Dim strFilter As String
    Dim lngflags As Long
    Dim varFileName As Variant
    
    strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
    & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
    
    lngflags = tscFNPathMustExist Or tscFNFileMustExist _
    Or tscFNHideReadOnly
    
    varFileName = tsGetFileFromUser( _
    fOpenFile:=True, _
    strFilter:=strFilter, _
    rlngflags:=lngflags, _
    strDialogTitle:="Please choose a file...")
    
    If IsNull(varFileName) Then
    Else
    Me![txtImageName] = varFileName
    Forms![tblPerson].Form.Requery
    End If
    
    cmdAddImage_End:
    On Error GoTo 0
    Exit Sub
    
    cmdAddImage_Err:
    Beep
    MsgBox Err.Description, , "Error: " & Err.Number _
    & " in file"
    
    Resume cmdAddImage_End
    End Sub
    
    Function setImagePath()
    Dim strImagePath As String
    On Error GoTo PictureNotAvailable
    strImagePath = Me.txtImageName
    Me.txtImageName.Locked = True
    Me.txtImageName.Enabled = False
    Me.ImageFrame.Picture = strImagePath
    Exit Function
    PictureNotAvailable:
    strImagePath = "C:\Windows\Wind.bmp"
    Me.ImageFrame.Picture = strImagePath
    End Function
    
    Private Sub cmdDeleteImage_Click()
    Me.txtImageName.Enabled = True
    Me.txtImageName.SetFocus
    Me.txtImageName.Locked = False
    Me.txtImageName.Text = ""
    Me.txtImageName.SetFocus
    Forms![tblPerson].Form.Requery
    Me.txtImageName.Locked = True
    Me.txtImageName.Enabled = False
    End Sub
    
    Private Sub txtImageName_AfterUpdate()
    setImagePath
    Forms![tblPerson].Form.Requery
    End Sub

    The image path is added to the picture path text field as expected but it's just the picture that isn't being displayed regardless of the requery at the end.


    I'm a bit stuck here so would appreciate any help

  2. #2
    meratigoerr's Avatar
    meratigoerr is offline Contributing User
    Join Date
    Jun 2011
    Location
    South Jersey
    Posts
    544
    Rep Power
    58
    In the code above I see your function setImagePath(). This is what sets your picture to the path that you're getting in the path field. I don't see anywhere that you're actually calling this function before the requery? The 'End Sub' right before it would suggest that this a function unrelated to your code for cmdAddImage_Click() (Someone please correct me if I misreading this code, I've done that before.....)

  3. #3
    June7's Avatar
    June7 is offline Moderator
    Join Date
    Apr 2009
    Location
    The Great Land
    Posts
    4,618
    Rep Power
    649
    What version of Access? Access 2007 introduced ControlSource property to Image control. This means no code required for dynamic display of images.
    I like to know if my suggestion helped you. One way to let me know is by clicking star at bottom left corner of post.
    Debug!Debug!Debug!http://www.cpearson.com/excel/debug.htm

  4. #4
    randle is offline Registered User
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0
    @ meratigoerr: I've simply cut this code from the sample database from the link above and changed the field names accordingly. I thought this function is being called as there's a requery right at the end!! Is this not doing what you say it should be?

    @June7: It's Access 2010. I've been looking at an alternative way to how I previously added pictures (as an OLE object) and this method was all I could find. Can you elaborate on the ControlSource property to Image control please?

    Thanks

  5. #5
    randle is offline Registered User
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0
    Actually forget that....I've just realised what you mean. I changed the Image frame control source to be the txtImageName field and it appears to have added the picture!!

    Super job thanks

  6. #6
    randle is offline Registered User
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0
    I would give you a start but doesn't appear to show one anywhere on the posts sorry

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Linking OLE Objects picture
    By karunanithi r in forum Microsoft Access Help
    Replies: 1
    Last Post: September 2nd, 2006, 07:40 PM
  2. Deleting picture in folder
    By stevenchoon in forum ASP Development
    Replies: 3
    Last Post: July 31st, 2006, 05:30 AM
  3. linking acess database/web page to my mp3's folder
    By novice69 in forum ASP Development
    Replies: 3
    Last Post: April 6th, 2004, 05:49 AM
  4. Linking to Every Folder and File
    By janusz_monkey in forum ASP Development
    Replies: 10
    Last Post: November 5th, 2003, 11:31 AM
  5. How to get file from a network mapped folder
    By YMU in forum ASP Development
    Replies: 2
    Last Post: September 10th, 2003, 09:45 PM

ASP Free Advertisers and Affiliates