Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81

    Unanswered: Inserting a file/photo into a Form

    I believe this has been asked before, but I can't get the search function to work. So will ask again...

    I am using Access 2000, how can I get a command button to attach an image or photograph to a form?

    A table has been established with a field called "photo" as an OLE object, what do I put down for the command button on the form to insert the picture? (the user should be asked to choose it from a directory/folder)

  2. #2
    Join Date
    May 2004
    Location
    Moscow, Russia
    Posts
    29

    pictures in forms

    I tried to use some ways of storage of pictures in a database.
    ole I think a way of use by the most unsuccessful
    At my site have some examples
    the most successful - use Activex keeping binary contents of a file in a field of the table

    Demonstration project MDB (352 KB)
    Demonstration project RAR (76 KB)

    Unfortunately a site in Russian
    this is autotranslation of source annotation:
    Storage of binary contents JPG, Gif a file in a binary field of a database.
    In connection with that that the given way has demanded a lot of a program code - by me has been made special ActiveX control
    approaches for: mappings of pictures in usual forms (not continiuos and not tabule) reports
    of Feature of the given way: saving on compressed files - about 15 times!!!

    As against other ways of storage of maps in a DB the data are stored in a database instead of on a disk

  3. #3
    Join Date
    Mar 2004
    Posts
    118
    Soring it in binary is pretty much the only way to store image data in a database. That and storing all the vector coordinates. For both you would need some tool that would do this.

    However the botch-job way would be to just store a 'link' to the immage and have a macro that runs that immage in an application of your choise.

    I'm unsure as to what you need. If its just a matter of making a form look pretty all you need to do is create an image "box" (one of the tools in form creation wizard).

    Hell you can even create 100 of them on top of eachother and set the controls to show/hide them depending on the records you select. Mind you it would be pretty hard to do maintenece on that form hehe.

  4. #4
    Join Date
    Mar 2004
    Location
    Glasgow, Scotland
    Posts
    107

    Suggestion

    This is the way I do it:

    - Just store hyperlink to photo in database. If u store as an OLE object it takes up more space...problematic when storing a large amount of photos.

    1) Add an image control to your from, for the purposes of the code below call it "imageJob".

    2) Then using the forms OnOpen event call the following function:

    Function setImagePath()

    Dim strImagePath As String
    On Error GoTo PictureNotAvailable

    strImagePath = Form_frmYourName.txtJob_PathToVisual.Value
    Form_frmYourName.imageJob.Picture = strImagePath
    Exit Function

    PictureNotAvailable:

    Exit Function

    End Function

    3) Use a text field ona form somewhere to get the path to the photo e.g. "c:\Access\photos\New.jpg"

    Hope this helps....

  5. #5
    Join Date
    May 2004
    Location
    Moscow, Russia
    Posts
    29
    Code:
    Private Sub Btn_Path_Click()
    Dim FName As String
    Dim result As Integer
    With Application.FileDialog(1) ' It is corrected : With Application.FileDialog(msoFileDialogOpen)
        .Title = "Select picture"
    
        .InitialFileName = "C:\" 'default path
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Picture files", "*.bmp; *.jpg", 1
        result = .Show
    
        If result = 0 Then Exit Sub
        FName = Trim(.SelectedItems.Item(1)) 
    End With
    on error resume next
    me.imageObj.Picture = FName
    End Sub
    Last edited by alexeyK; 05-26-04 at 05:07.

  6. #6
    Join Date
    Mar 2004
    Location
    Glasgow, Scotland
    Posts
    107
    Nice code, didn't realise that you could manipulate the common open file dialog box like that. Cheers

  7. #7
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81

    FileDialog

    Your right, I don't believe that'll work.

    I recieve a visual basic error of Compile Error: Method or data member not found in the debuger with FileDialog highlight.

  8. #8
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81
    I've gotten everything to work using it but am stumped on one thing.

    It there a command button that can be used to have the a user choose the relative path of the picture to display?

  9. #9
    Join Date
    Mar 2004
    Location
    Glasgow, Scotland
    Posts
    107
    The answer is in the replies above, see Private Sub Btn_path_Click() as posted by alexeyk....

  10. #10
    Join Date
    May 2004
    Location
    Moscow, Russia
    Posts
    29

    re

    I have updated examples:
    has added English captions for controls of the form and the filedialog button


    if filedialog not work :

    add reference to microsoft office library

    or use this string for calling filedialog

    Code:
    With Application.FileDialog(1)
    Last edited by alexeyK; 05-26-04 at 05:08.

  11. #11
    Join Date
    Sep 2003
    Location
    Spokane, WA
    Posts
    81

    Exclamation Here's Where I'm At...

    I've attached the form/table for you to see what I have.

    The path text box pulls the picture into the form wonderfully.

    Where I am lost is placing a button (or something) in the form to have the user choose the file to place in the text box for the photo.

    Let me tell you what I'm doing;

    I work as a security officer in a large exclusive (kind of) privately owned hotel.

    We often trespass people and take a digital picture which goes to E:\security of our computer.

    I have a form built to tell a user about that person and have a text box and picture frame all working ok with each other to pull the picture off of e:\security.

    In trying to make it as easy as possible for the non-computer literate people I'd like them to be able to use that command button to choose the file and have it automatically paste into the text box which will automatically update the form with the picture.

    I've tried using Insert, Activex control, Common Dialog control, from the menu but get a windows error that the OLE server isn't registered and have had *NO* luck at all in troubleshooting any of this via the Microsoft web site.

    So....suggestions?
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •