Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2004
    Posts
    77

    Unanswered: Variable not defined?!?

    hi guyz. thx to those for replying my last qns and viewing it. this time i have this problem. i'm currently trying to create a file picker dialog. following the Northwind example, i tried to do the same for my database. but strangely, after i declared "Option Explicit", i kept on getting this "Compile error: Variable not defined" error whenever my code reaches this line:

    With Application.FileDialog(msoFileDialogFilePicker)
    .title = "Select an Image to add in"
    .Filters.Add "All Files", "*.*"
    .......
    .......
    end with

    anyone with any ideas why this is happening to my database but not in the Northwind example database? I either can't find the the variable that is not declared or i'm not skilled enough to find it...
    Last edited by chanjw; 12-14-04 at 06:05. Reason: Missed out info...

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    The msoFileDialogFilePicker is probably the variable that's giving you a problem.
    It's actually a global constant that is part of the Microsoft Office Object Library. If that reference isn't installed on your computer, you would have this problem.

    From any module window, go to Tools - References and check the "Microsoft Office 10.0 Object Library" and click OK. Your computer may have a version other than 10.0, depending on your version of office. Just select the highest number available.
    Inspiration Through Fermentation

  3. #3
    Join Date
    Mar 2004
    Posts
    77
    sorry RedNeckGeek, but it still doesn't work. i've imported the Employees form from Northwind and it worked in my database, while mine own form doesn't! what is going on here?

  4. #4
    Join Date
    Mar 2004
    Posts
    77
    i tried another way. i commented out the "Option Expicit" line, and another type of error pops up. it goes like this "Runtime error '-2147467259 (80004005) Method "FileDialog" of "_Application" failed". I'm pretty sure this error is also somehow linked to the "msoFileDialogFilePicker" line. but i still do not know what is it i'm doing wrong. will someone please enlighten me?

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    There is a Type declaration that has not been accomplished yet. It should look something like this:

    Code:
    Type OPENFILENAME
    	lStructSize As Long
    	hWndOwner As Long
    	hInstance As Long
    	lpstrFilter As String
    	lpstrCustomFilter As Long
    	nMaxCustrFilter As Long
    	NFilterIndex As Long
    	lpstrFile As String
    	nMaxFile As Long
    	lpstrFileTitle As String
    	nMaxFileTitle As Long
    	lpstrInitialDir As String
    	lpstrTitle As String
    	Flags As Long
    	nFileOffset As Integer
    	nFileExtension As Integer
    	lpstrDefExt As String
    	lCustrData As Long
    	lpfnHook As Long
    	lpTemplateName As Long
    End Type
    And should be located somewhere within the declarations section of your code module. Re-check your code sample. You missed supplying this for your module.


  6. #6
    Join Date
    Mar 2004
    Posts
    77
    CyberLynx, its true that i am missing these declarations. where must i place them? in a module? or at the start of the code for the form?

  7. #7
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    With Application.FileDialog(msoFileDialogOpen)
    ...
    End With
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  8. #8
    Join Date
    Mar 2004
    Posts
    77
    i placed it inside the part where r123456 suggested and i got "Compile error:Invalid inside procedure"

    this is how i placed the codes:

    Sub getFileName()

    Dim fileName As String
    Dim result As Integer

    Type OPENFILENAME
    lStructSize As Long
    hWndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As Long
    nMaxCustrFilter As Long
    NFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    Flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustrData As Long
    lpfnHook As Long
    lpTemplateName As Long
    End Type
    With Application.FileDialog(msoFileDialogFilePicker)
    ....
    End With

    End Sub

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    chanjw
    the error message is pretty specific "Compile error:Invalid inside procedure" suggests that the code is not valid if declared inside the procedure. So move it to the top of module (after the option explicit statement)

  10. #10
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Sorry, my previous post was not relevant.

    The problem is becuase of a missing reference, specifically the Microsoft Office Object Library, as already mentioned.

    In the VBA code editor:

    Tools => References.
    Last edited by r123456; 12-15-04 at 07:47.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  11. #11
    Join Date
    Mar 2004
    Posts
    77
    hey, RedNeckGeek and r123456, u guys are right! it is the Microsoft Office Library 10.0. I made a mistake and instead of checking the Office Library, i checked the Access Library. its working now. thx guyz. CyberLynx, thx for ur help anyway.

Posting Permissions

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