Compile Error

  • Thread starter Thread starter ksandova
  • Start date Start date
K

ksandova

I am using this code to compact and repair an access
database and it generates a compile error "Function call
on left side of assignment must return Variant or Object"

What did I do wrong?

Here is the code:

Sub tests()
Dim MDB1 As String, MDB2 As String
MDB1 = "C:\Comp0001.mdb"
MDB2 = "C:\Comp0002.mdb"

RepairDatabase(MDB1, MDB2) = False
End Sub
Function RepairDatabase(strSource As String, _
strDestination As String) As Boolean
' Input values: the paths and file names of
' the source and destination files.

' Trap for errors.
On Error GoTo error_handler

' Compact and repair the database. Use the return
value of
' the CompactRepair method to determine if the file was
' successfully compacted.
RepairDatabase = _
Application.CompactRepair( _
SourceFile:=strSource, _
DestinationFile:=strDestination, _
LogFile:=True)

' Reset the error trap and exit the function.
On Error GoTo 0
Exit Function

' Return False if an error occurs.
error_handler:
RepairDatabase = False

End Function
 
Sub tests()
Dim MDB1 As String, MDB2 As String
MDB1 = "C:\Comp0001.mdb"
MDB2 = "C:\Comp0002.mdb"


'RepairDatabase(MDB1, MDB2) = False <- change this ...
RepairDatabase MDB1, MDB2 '<- to this

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
That worked!
Thank You!

-----Original Message-----
Sub tests()
Dim MDB1 As String, MDB2 As String
MDB1 = "C:\Comp0001.mdb"
MDB2 = "C:\Comp0002.mdb"


'RepairDatabase(MDB1, MDB2) = False <- change this ...
RepairDatabase MDB1, MDB2 '<- to this

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E- mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e- mail, you'll find
a useable e-mail address at the URL above.





.
 
Back
Top