Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sudden Run-time Error -2147024809

Status
Not open for further replies.

MeldrethMan

Technical User
Feb 3, 2012
69
GB

Any help would be appreciated.

A run-time error -2147024809, 'Invalid procedure call or argument' has suddenly appeared in a procedure that worked fine in earlier editions. The changes I've made since then have been cosmetic ones on form and report formats.

I'm using Call AllCodeToTextFile("C:Code", "txt") on a form's command button and the procedure code is as below.

Debug highlights the middle line of the For statement, strmod = VBE. etc

When it works this is a very useful way of getting all code posted out to a text file.

Code:
Sub AllCodeToTextFile(strFolder As String, strFileExt As String)
     Dim fs As Object
     Dim F As Object[highlight #FCE94F][/highlight]
     Dim strMod As String
     Dim mdl As Object
     Dim i As Integer

     Set fs = CreateObject("Scripting.FileSystemObject")
     If Right(strFolder, 1) = "" Then
        'Do Nothing
     Else
        strFolder = strFolder & ""
     End If

' Establish the file name using the CurrentProject Name
     strFolder = (strFolder & Replace(CurrentProject.Name, ".", "") & "." & strFileExt)
'Set up the file.
     Set F = fs.CreateTextFile(strFolder)
'For each component in the project ...
     For Each mdl In VBE.ActiveVBProject.VBComponents
         i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
         [highlight #FCE94F]strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.Lines(1, i)[/highlight]
         F.WriteLine String(55, "=") & vbCrLf & mdl.Name & vbCrLf & String(55, "=") & vbCrLf & strMod
     Next mdl
     MsgBox "Code has been saved to " & strFolder
'Close eveything
     F.Close
     Set fs = Nothing
End Sub
 
Thanks Duane but this gives a 'permission denied' error instead, on the line strFolder = strFolder & ""

I've checked the working copy and AllCodeToTextFile("C:Code", "txt") definitely works, somehow sending the text file to My Documents.

In the latest attempt I went back to Remou's code here
and copied the call and procedure again.

I find it now produces part of the text file but stops short with Error -2147024809 Invalid procedure call or argument in procedure AllCodeToTextFile.

I can't see what decides the order the code blocks are sent as they are not alphabetic. So I can't yet see where the code now halts as there isn't the same Debug option in the error message.

One thing for sure is there are several temporary reports like Report_~TMPCLP505791 that I can't remove.
 
>somehow sending the text file to My Documents

Yes, well it would. The FileSystemObject parses the path you give it and tries to make something legitimate out of it. See the following

MsgBox CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("C:")
 
Whenever that happens to me it is because there is a permissions problem somewhere on the folder or one of the files I am using. Are you trying to copy over a read-only file? Any chance you do not have read/write permission to the folder?
 

Thanks for all the suggestions so far, much appreciated.

Stepping through the procedure the thing that's tripping it up is one of the temporary forms, Form_~TMPCLP624811.

As before there are also several temporary reports. For all TMP files the Remove option is greyed out so what's the technique for getting rid of them?
 
Those are remnants of deleting objects from the database and Access should normally clean them up as soon as the original object is properly deleted. However, they sometimes get orphaned and, since they are part of an internal housekeeping exercise, you don't have proper access to them - hence the error message (and the greyed out option)

To get rid of them, compact the database.
 

Thanks Strongm, already did a compact & repair but it didn't remove them. Seems like the only way is to export everything to a new database, huge task. Since the database works fine I'm inclined to leave it as is and just use On Error Resume Next so the code export routine completes.
 
>Seems like the only way is to export everything to a new database

Indeed, if compacting doesn't work that is the other method. Ah well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top