active x cant create object in access2000 runtime

tanzania

Registered User.
Local time
Today, 12:37
Joined
Oct 20, 2006
Messages
91
Hi, i am using the following code to open another access database. it works fine in fuilltime but when i install a runtime version I get an 'active x cant creat object' error. Does anyone knwo why this is?

Dim appAccess As Object
Const strPathToBackup = "C:\interim.mdb"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strPathToBackup
appAccess.Visible = True 'do not show database
appAccess.Run "Test"
appAccess.CloseCurrentDatabase

Cheers

Tania
 
It might have to do with the fact that if you could create Access databases via code in the run time Microsoft would have less control over people making databases using something that isn't supposed to be able to create or edit databases. That's only a guess, and hopefully someone can correct me and say that you can actually do it, but that's the only reason I can think of why this would work in the full version but not the runtime.
 
that certainly makes sense, but this is really showing the weaknesses in runtime.the reason i was needing to use the access object was to try get around the apiCopyFile not working in the runtime (to copy an open database).
 
Try doing it this way by using this function (replacing the applicable paths with yours):

Code:
Public Function BUDatabase()
    Dim strFile As String
    Dim strNewPath As String

    strFile = "C:\Temp\CopyDb.cmd"
    strNewPath = "Copy " & Chr(34) & "C:\Temp\Test.mdb" & Chr(34) & " " & Chr(34) & "C:\Temp\Test.bak" & Chr(34)

    Open strFile For Output As #1
    Print #1, strNewPath
    Print #1, "Del " & Chr(34) & strFile & Chr(34)
    Close #1
    Shell strFile
    DoCmd.Quit
End Function

And then just call it. It should work in both full and runtime.
 
thanks for that, ill give a try at work tomorrow-fingers xed!
 
The following function works in both full and RunTime environments. I use it all the time. It returns True if the copy was successful and False if it was not:
Code:
Public Function fCopy( _
    ByVal sFile As String, _
    ByVal dFile As String) _
    As Boolean
On Error GoTo fCopy_Error

    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.GetFile(sFile)
    MyFile.Copy (dFile)
    Set MyFile = Nothing
    Set fso = Nothing
    fCopy = True

Exit Function

fCopy_Error:
    fCopy = False

End Function

Call the function with something like:
Code:
fCopy "C:\Temp\Test.mdb", "C:\Temp\Test.bak"
 
The following function works in both full and RunTime environments. I use it all the time. It returns True if the copy was successful and False if it was not:
Code:
Public Function fCopy( _
    ByVal sFile As String, _
    ByVal dFile As String) _
    As Boolean
On Error GoTo fCopy_Error

    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.GetFile(sFile)
    MyFile.Copy (dFile)
    Set MyFile = Nothing
    Set fso = Nothing
    fCopy = True

Exit Function

fCopy_Error:
    fCopy = False

End Function

Call the function with something like:
Code:
fCopy "C:\Temp\Test.mdb", "C:\Temp\Test.bak"

Will it work with the database opened in Exclusive mode?
 
My method should work fairly well then as it would back up the thing if it is closed and no one else is in it. If someone else is in it, it won't copy and when the last person goes out it will.
 
Hi,

I tried your method Bob and it works :-) Thanks so much for the help! I opted not to try the other due to the reference required for the scripting object which I have also found to be problematic in the runtime.

Cheers

Tania
 

Users who are viewing this thread

Back
Top Bottom