Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Get File Name Routine (WXP Access 2002)

    I am trying to duplicate the Employee Image portion of the Northwind sample database, and I have it all working except for the get filename routine. When I call on the routine notthing happens. I'm wondering if I'm missing the "FileDialog ..." application that appears in the 7th line of the code.
    Also, is there a way to force the picture to fit the size of the Image Frame, or must the pictures be stored in exactly the size necessary to fit the frame?

    Any advice would be welcome.

    Here's what's in Northwind:

    ==============================
    Sub getFileName()
    ' Displays the Office File Open dialog to choose a file name
    ' for the current employee record. If the user selects a file
    ' display it in the image control.
    Dim fileName As String
    Dim result As Integer
    With Application.FileDialog(msoFileDialogFilePicker)
    .Title = "Select Employee Picture"
    .Filters.Add "All Files", "*.*"
    .Filters.Add "JPEGs", "*.jpg"
    .Filters.Add "Bitmaps", "*.bmp"
    .FilterIndex = 3
    .AllowMultiSelect = False
    .InitialFileName = CurrentProject.path
    result = .Show
    If (result <> 0) Then
    fileName = Trim(.SelectedItems.Item(1))
    Me![ImagePath].Visible = True
    Me![ImagePath].SetFocus
    Me![ImagePath].Text = fileName
    Me![FirstName].SetFocus
    Me![ImagePath].Visible = False
    End If
    End With
    End Sub

    =====================================

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get File Name Routine (WXP Access 2002)

    In the Visual Basic Editor, select Tools | References...
    You must locate and tick the check box for "Microsoft Office 10.0 Object Library", then click OK.

    Remark: do you have "Require Variable Declaration" ticked in Tools | Options...?
    If not, do so now. It'll save you a lot of grief in the end (though you may curse first)

    Image controls have a Size Mode property. It can have three values: Clip, Stretch and Zoom. You probably want Zoom, this maximizes the size of the picture within the control without distorting it.

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Get File Name Routine (WXP Access 2002)

    Hi Hans,

    In reverse order to your reply:

    I found the Zoom control, and that works OK.

    I now have the "Variable Declaration" ticked. (No error messages, so I assume they've all been declared.)

    The "Microsoft Office 10.0 Object Library" box has been checked all along. So I must be missing something else.

    I also notice that the first time I go to a record the picture appears, but if I go to another record and then return the picture is not there. Should I be doing some kind of requery or something each time I return to a record?

    Thanks again,

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get File Name Routine (WXP Access 2002)

    Apparently, we're talking at cross purposes. I took "When I call on the routine notthing happens" to mean that the Open dialog wasn't displayed, so I tried to think of a possible reason for that.

    The code you posted just sets a text field, it doesn't modify the image control. Say that the image control is named imgPicture. You should add

    Me.imgPicture.Picture = Me.ImagePath

    This instruction should also be called in the On Current event of the form; you must add error handling to avoid error messages if the image is not available.

    Note 1:

    Me![ImagePath].Visible = True
    Me![ImagePath].SetFocus
    Me![ImagePath].Text = fileName
    Me![FirstName].SetFocus
    Me![ImagePath].Visible = False

    is very inefficient. It can be replaced by this single line:

    Me.ImagePath = fileName

    Note 2:

    See <post#=296892>post 296892</post#> for a working example of handling images in forms and reports. It uses another method for presenting the Open dialog, since it is meant to work in older versions of Access too (FileDialog is new in Access 2002).

  5. #5
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Get File Name Routine (WXP Access 2002)

    Hi again,

    The problem was that I didn't have all the proper Reference selected.Once I did the problems went away.

    Thanks for your suggestions.

Posting Permissions

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