CopyObject gets "Illegal function call" error 
Author Message
 CopyObject gets "Illegal function call" error

Version = Access 2.0
O/S = Win95

I'm getting error 5, "Illegal function call" on the CopyObject action in
the following code.  Can anyone give me a clue as to why?  It doesn't
happen consistently, but I haven't yet figured out what the determining
conditions are.  The function seems to work fine when called from a macro,
but gives me this error intermittently when called from another function in
the same module.
________________________

calling statement:

    Result = CopyForm("Orders Prototype", "Orders")
________________________

Function CopyForm (SourceName As String, DestinationName As String) As Integer

' This function copies a prototype form to replace a temporary form.

    ' Make sure both source & destination forms are closed
    DoCmd Close A_FORM, SourceName
    DoCmd Close A_FORM, DestinationName

        If IfFormExists(DestinationName) Then DoCmd DeleteObject A_FORM,
DestinationName

    DoCmd CopyObject , DestinationName, A_FORM, SourceName

    CopyForm = True

End Function
________________________

Right after the error occurs I use the immediate window to print out the
values:

print DestinationName, A_FORM, SourceName
Orders         2            Orders Prototype

Both of these forms exist prior to running the code.  The destination form
is properly deleted.  This code is in an independent module, not in one of
the two forms.

In case it's relevant, here's the IfFormExists function referred to above:
________________________

Function IfFormExists (FormName As String)

    Dim FoundIt As Integer
    Dim MyDB As Database
    Dim X As Integer

    Set MyDB = CurrentDB()
    FoundIt = False
    X = 0

    Do While X < MyDB.containers("forms").documents.count And FoundIt = False

            If FormName = MyDB.containers("forms").documents(X).name Then
FoundIt = True

        X = X + 1
    Loop

    ' Return answer to macro
    Forms!Constants!IfExists = FoundIt

    ' Return answer to module
    IfFormExists = FoundIt

End Function
________________________

I don't know if it's relevant, but I'm frequently turning Echo and
SetWarnings on and off throughout the program, although deliberately
setting them on or off doesn't seem to affect the CopyForm function in any way.

If you have any suggestions at all, I'd love to hear them.

Thanks,

Paul



Fri, 18 Feb 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Enumerating References - "Illegal Function Call"

2. "Illegal function call" when loading program

3. Error "Illegal use of property"?

4. Calling a VBScript Function from "onChange"

5. Calling the "Scan" Function in Acrobat

6. "Call default Internet connection"-function

7. "Pure Virtual Function called"

8. "Pure Virtual Function Call" Problem

9. "Program Used for Illegal Purpose"

10. Getting "Changed database context" error

11. VB6 "illegal opeation" message in Win95

12. Getting "Changed database context" error

 

 
Powered by phpBB® Forum Software