Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    When i debug print it says the variable has not yet been made in this context.

    I have tried basicly everything i can to understand why the code in the sample database works and not in the real one.

    I have compared the library's and the only thing differen i see is the Microsoft Office 14.0 Access database object library. But i cant turn that on in the real db because of a conflicting library) , However if i uncheck it at the sample database, it code runs flawless.



    My code was in form_current and in the sample under a button. So i duplicated that situation, same effect (type mismatch) returns.

    I have tried with and without trailing behind the path to the directory, no type mismatch, but no results either.
    Ive tried making a new textbox to display the results on my form, that didnt help.

    The funny thing is, at the point the error occurs and when im hovering with my mouse over the error it says :

    Set ObjFolder = Nothing
    and at the strFile is see the correct path to the directory i wanna check.

    I am clueless ..

  2. #17
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Do you have a reference set to "Microsoft Scripting Runtime"? I has to set that reference to get the code to run.

    I think there is a logic error in the FOR loop. "ctrlGetFileCount" (control on form?) will be (re)set to the dir count every loop if the extension is not ".db". If the file with ".db" happens is the 20th file of 40, when the 20 th file is reached, the count is reduced to 39. But on the next loop, the file count is back at 40 (objFolder.Files.Count).

    Consider this:
    Code:
        Dim strFile As String
        Dim ctrlGetFileCount As Integer
        strFile = "C:\Maindir\Subdir1\Subdir2\"
    
        If Len(Dir(strFile)) = 0 Then
            ctrlGetFileCount = 0
        Else
            Dim fsoFile As New FileSystemObject
            Dim objFolder As folder
            Dim objFile As File
            Set objFolder = fsoFile.GetFolder(strFile)
    
            ctrlGetFileCount = objFolder.Files.Count
            For Each objFile In objFolder.Files
    
                If InStr(objFile.Name, ".db") Then
                    ctrlGetFileCount = objFolder.Files.Count - 1
                End If
            Next
            Set objFolder = Nothing
        End If
    One other thing. Do you have the following two lines as the top two lines in the (every) module?
    Code:
    Option Compare Database
    Option Explicit

  3. #18
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Hi ssanfu, Yes i have option explicit in most of my forms, and especially this one.
    Scripting runtime was also preset.

    Your code didnt work on my sample database and the new one either.

    However i fixed the problem..

    I made a new database, copied all objects within and added references to the libraries.
    And it works !!!
    A risky operation because i have a LOT of objects, and 8000+ lines of code. And im probably not going to be able to go to sleep tonight worrying that something did go wrong during the copy.

    My database was made in 2007 on ACC 2003 and upgraded it on the go till now.
    I hope i fixed the problem now, refrences too old or something like that.
    Seems you cannot upgrade old products without being punnished for it :P

  4. #19
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    i have a LOT of objects, and 8000+ lines of code.
    Be sure to compile your code as you write it. Understand that the Graphic Interface designer and the VBA editor/IDE are two different programs. Save often. Pay attention to how many different forms, reports, etc. you are making design changes to at a given time. Try to limit the number of objects and or modules to one, when possible.

  5. #20
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Probably a little corruption started in the old file. Did you convert the dB to A2010 format (accdb)?

    Did you understand the logic changes to the code I made?

    Great that you fix the problem.

    Remember the 3 rules pf computing:
    1) Backup,
    2) Backup,
    and
    3) Backup!

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. using mdb files which are backed up hourly into zip files
    By Robbie MacKinnon in forum Access
    Replies: 3
    Last Post: 05-05-2015, 05:02 AM
  2. Replies: 4
    Last Post: 05-15-2014, 12:49 PM
  3. Replies: 2
    Last Post: 05-21-2012, 02:06 PM
  4. Excluding data
    By Vic1980 in forum Queries
    Replies: 3
    Last Post: 03-14-2012, 06:34 AM
  5. Replies: 1
    Last Post: 02-21-2011, 09:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums