
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