Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2010
    Posts
    11

    Unanswered: (msoFileDialogFilePicker) error problem

    Hi;

    I want to make a function in my form to insert a picture in it. I use the code as same as Northwind Db.

    However I got compile error "variable not found" and "msoFileDialogFilePicker" syntax has been highlighted.

    I go for Tool --> References and I found the square box for Microsoft Access 11.0 Object Library is already been checked.

    So anyone get any idea how to solve this problem? Thanks for your attention.
    Attached Thumbnails Attached Thumbnails VBA err.GIF   err2.GIF  
    Last edited by Zul77; 02-20-10 at 11:39.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    The FileDialog object is a member of Microsoft Office xx.x Object Library (MSO.dll) and you don't have any reference to it in your project. In your case, it should be: Microsoft Office 12.0 Object Library (or possibly: Microsoft Office 11.0 Object Library).
    Attached Thumbnails Attached Thumbnails References001.jpg  
    Have a nice day!

  3. #3
    Join Date
    Feb 2010
    Posts
    11
    Thanks. I'm sorry, I'm not quite clear with that. Do you mean that I need to add Microsoft Office 12.0 Object Library? I'm using Access 2003. I think it's quite impossible to upgrade Microsoft Office 11.0 Object Library (in access 2003) into Microsoft Office 12.0 Object Library.

    Or, do you mean I need to add some VB code to the Northwind code so that it will refer to Microsoft Office 11.0 Object Library?

    This is my code:

    Option Compare Database
    Option Explicit
    Dim path As String

    Private Sub AddPicture_Click()
    ' Use the Office File Open dialog to get a file name to use
    ' as an employee picture.
    getFileName
    End Sub

    Private Sub Form_RecordExit(Cancel As Integer)
    ' Hide the errormsg label to reduce flashing when navigating
    ' between records.
    errormsg.Visible = False
    End Sub

    Private Sub RemovePicture_Click()
    ' Clear the file name for the employee record and display the
    ' errormsg label.
    Me![ImagePath] = ""
    hideImageFrame
    errormsg.Visible = True
    End Sub

    Private Sub Form_AfterUpdate()
    ' Requery the ReportsTo combo box after a record has been changed.
    ' Then, either show the errormsg label if no file name exists for
    ' the employee record or display the image if there is a file name that
    ' exists.
    On Error Resume Next
    showErrorMessage
    showImageFrame
    If (IsRelative(Me!ImagePath) = True) Then
    Me![ImageFrame].Picture = path & Me![ImagePath]
    Else
    Me![ImageFrame].Picture = Me![ImagePath]
    End If
    End Sub

    Private Sub ImagePath_AfterUpdate()
    ' After selecting an image for the employee, display it.
    On Error Resume Next
    showErrorMessage
    showImageFrame
    If (IsRelative(Me!ImagePath) = True) Then
    Me![ImageFrame].Picture = path & Me![ImagePath]
    Else
    Me![ImageFrame].Picture = Me![ImagePath]
    End If
    End Sub
    Private Sub Form_Current()
    ' Display the picture for the current employee record if the image
    ' exists. If the file name no longer exists or the file name was blank
    ' for the current employee, set the errormsg label caption to the
    ' appropriate message.
    Dim res As Boolean
    Dim fName As String

    path = CurrentProject.path
    On Error Resume Next
    errormsg.Visible = False
    If Not IsNull(Me!Photo) Then
    res = IsRelative(Me!Photo)
    fName = Me![ImagePath]
    If (res = True) Then
    fName = path & "\" & fName
    End If

    Me![ImageFrame].Picture = fName
    showImageFrame
    Me.PaintPalette = Me![ImageFrame].ObjectPalette
    If (Me![ImageFrame].Picture <> fName) Then
    hideImageFrame
    errormsg.Caption = "Picture not found"
    errormsg.Visible = True
    End If
    Else
    hideImageFrame
    errormsg.Caption = "Click Add/Change to add picture"
    errormsg.Visible = True
    End If

    End Sub

    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

    Sub showErrorMessage()
    ' Display the errormsg label if the image file is not available.
    If Not IsNull(Me!Photo) Then
    errormsg.Visible = False
    Else
    errormsg.Visible = True
    End If
    End Sub

    Function IsRelative(fName As String) As Boolean
    ' Return false if the file name contains a drive or UNC path
    IsRelative = (InStr(1, fName, ":") = 0) And (InStr(1, fName, "\\") = 0)
    End Function

    Sub hideImageFrame()
    ' Hide the image control
    Me![ImageFrame].Visible = False
    End Sub

    Sub showImageFrame()
    ' Display the image control
    Me![ImageFrame].Visible = True
    End Sub

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You need to add a reference to the Office 12.0 Object Library, as shown on the picture I joined to my first answer. I mentioned the possibility of Office 11 because I was not sure which version of Access you use. With 2003 it's Office 12.
    Have a nice day!

  5. #5
    Join Date
    Feb 2010
    Posts
    11
    I think for a while, I need to leave the function behind. I wish I know how to make a function where a user can put their school logo some day. BTW, here I have attached my file. Hopefull you get the idea how I'm going to make his happen.

    Thank you very much for your help.
    Attached Files Attached Files

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Are you sure that the database you joined to your last message is the one you're actually using? I noticed several problems that prevent it to be functional and it's not possible to compile its code.

    Among others:

    1. The function getFileName tries to use the FileDialog object while no reference to the Microsoft Office 12.0 Object Library exist in your project (as mentioned before).

    2. Several lines of code reference an errormsg object (errormsg.Visible = False, etc.) that does not exist, is not declared nor instanciated .

    3. Several objects (e.g. tblStudentEvent SubForm) do not respect the usual naming conventions (spaces, etc.) and are not properly addressed:
    Code:
    If tblStudent_subform.NewRecord Then Me.tblStudentEvent SubForm.Requery
    should probably be:
    Code:
    If tblStudent_subform.NewRecord Then Me.[tblStudentEvent SubForm].Form.Requery
    (and the name of the subform would better be tblStudentEvent_SubForm, without spaces).

    4. The code references objects that do not exist in the context of its execution:
    Code:
    cboEvent = Me.cboEvent.ItemData(0)
    (There is no cboEvent object in the frmlStudentEvent Subform form).

    5. The same frmlStudentEvent Subform form does not contain any control, just some code that reference objects that do not exist (Command14_Click, cboCategory_AfterUpdate, tblStudent_subform).
    Have a nice day!

  7. #7
    Join Date
    Sep 2006
    Posts
    265
    I can see what you are doing but there associating images to your Employee's should be purely referential. If you think about it, this is from my web experiences, it the image is not there is going to immediately apparent, the only reason a Blank Image frame is used is for page rendering, taking up space.

    You can do most of image handling with:
    Code:
    Function GetPicture()
    
    Dim FullPath As String
    
        With CodeContextObject
            FullPath = GetImageDir & .[Image File]
    
            If Dir([FullPath]) <> Empty Then
                .[ImageControl].Visible = True
                .[ImageControl].Picture = FullPath
            Else
                .[ImageControl].Visible = False
            End If
        End With
    
    End Function
    Simon

  8. #8
    Join Date
    Feb 2010
    Posts
    11
    Thank you so much Sunndho for spending your time studying my code. Actually I'm just a beginner and not well versed with VB code. I just get the code from Northwind sampel. Maybe I miss something from the code or maybe I should find any other sample. For now I'm going to remove the insert picture code until found the better one.

    About cboEvent = Me.cboEvent.ItemData(0) syntax, also I just get this from another sample, but it seems it not bother my project.

    About frmlStudentEvent Subform, actually it is a dummy form because I'm not sure any mistake that I've done. I got an error pop up saying that an error related to frmlStudentEvent Subform. So after I made the dummy subform the error pop up gone (You can notice the error when you delete the frmlStudentEvent Subform )

    Maybe after completing my simple Db, I'll focus my study on VB programming to get know more about the coding.

    Thanks again for your willingness to help

  9. #9
    Join Date
    Feb 2010
    Posts
    11
    Thanks SimonMT. I'm sorry, may I know where sould I put the code? Is it on cmd button on click?

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    As far as the FileDialog object is concerned, simply add a reference to the Microsoft Office 12.0 Object Library to your project and your code will work.
    Have a nice day!

  11. #11
    Join Date
    Feb 2010
    Posts
    11
    I have read a few article from various sites including this one:

    Microsoft Access tips: Solving Problems with Library References

    I believe Microsoft Office 12.0 Object Library is meant for Access 2007 version and the one that I use now is Access 2003. I would rather remove the code because it will not compatible with previous version esspecially Access 2003 that I'm using now.

    Is it possible to change the code so that it will not need Microsoft Office 12.0 Object Library but Microsoft Office 11.0 Object Library?

  12. #12
    Join Date
    Sep 2006
    Posts
    265
    A Forms On Current event

    On a Report
    If the image is in the Detail Section On Format or On Print

    Simon

  13. #13
    Join Date
    Feb 2010
    Posts
    11
    Thanks SimonMT. However I got error massage with that code. Maybe I put it wrongly.... any idea?
    Attached Thumbnails Attached Thumbnails on current.GIF  

  14. #14
    Join Date
    Sep 2006
    Posts
    265
    You use [ImagePath] I use [Image File] or you may use ImageFile. The ImageControl need to be on the Form. Whatever you use you need to consistent. I use functions rather than Subs attached to the Form.

    The GetImageDir is used because I need variable locations for the Images. If your [Image Path is the full file name Directories + File + extension, you don't need GetImageDir. If it is not then:

    Code:
    Function GetImageDir() As String
    
        GetImageDir = "C:/inetpub/wwwroot/Demo/"
    
    End Function
    You will need to out the right Directories etc in this Function and this depends on the location of the Images.


    Simon

Posting Permissions

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