Link to home
Start Free TrialLog in
Avatar of snyperj
snyperjFlag for United States of America

asked on

Need some additional help with this script to update front ends

Nick67 was gracious to share a method to automatically update front ends in this post:
https://www.experts-exchange.com/questions/27319609/Can-a-front-end-be-shared-by-more-than-one-user.html


I am trying to get this to work in my environment... I am almost there but needs a little help with my settings... (at least I hope that is all it is....)

1st question:  My app is very small and copies very quickly.  Is there a way to hide the command window from displaying.  It blinks on and off in about 2 seconds and I can see it confusing some people, WHATWAZZAT!?

2nd question:  I have a mixed environment of Access 2000, 2007 and soon to be 2010.
Access 2000 starts up pretty quickly but I noticed that Access 2007 opens to main page ("Getting Started with Microsoft Office Access") and then goes into the database.  Is there any way to prevent that from showing... ?

3rd question:  This will not run with the Access2007 runtime version.  It bombs with line 112:  ActiveX can't create object "Access.Application"   Is there another way to do it for use with the run time?  Unfortunately we have many desktops with Office Standard (No Access installed.)


Thanks!


'declare an object to be a filesystem object
Public fs
'declare an object to be a MS Access application
Public acApp
 'declare a wscript shell
Public WshShell

Main()

'-------------------------------------------------------------------------------------------------------------------------------------------
Sub Main()
dim MyConn
dim MyConn1
Dim LocalSplit
Dim ServerSplit
Dim x

OpenCmdWindow()



CheckDeployment()

If fs.FileExists("G:\General\database\TimeSheet\deploy\ver.txt") then
    Set MyConn= fs.OpenTextFile("G:\General\database\TimeSheet\deploy\ver.txt",1, true)
    ServerSplit = Split(MyConn.readall, ".")
    MyConn.Close
end if

If fs.FileExists("U:\db\TimeSheet\ver.txt") then
    Set MyConn1= fs.OpenTextFile("U:\db\TimeSheet\ver.txt",1, true)
    LocalSplit = Split(MyConn1.readall, ".")
    MyConn1.Close
else
    LocalSplit =Split("0.0.0.0", ".")
end if

set myconn = nothing
set myconn1 = nothing

If UBound(LocalSplit) <> UBound(ServerSplit) Then
        Call CopyUpdate()
        FireDB()
        Exit Sub
End If

For x = 0 To UBound(LocalSplit)
    If cint(ServerSplit(x)) > cint(LocalSplit(x)) Then
        Call CopyUpdate()
        FireDB()
        Exit Sub
    End If
Next

if fs.FileExists("U:\db\TimeSheet\time_capture_fe_Backup.mdb") then
    Call KillBad()
    Call CopyUpdate()
    FireDB()
    Exit Sub
end if


FireDB()

end sub

'------------------------------------------------------------------------------------
private Sub CopyUpdate()
Dim BuiltPath
Dim userpath

userpath= "G:\General\database\TimeSheet\deploy\time_capture_fe.mdb"
BuiltPath = "U:\db\Timesheet"
TempPath = "U:\db\Timesheet\temp"

If fs.FolderExists(BuiltPath) = False Then
    fs.CreateFolder BuiltPath
    fs.copyfile "G:\General\database\TimeSheet\deploy\dynaPFD.dll", "U:\db\TimeSheet\dynaPDF.dll", -1
    fs.copyfile "G:\General\database\TimeSheet\deploy\strStorage.dll", "U:\db\TimeSheet\strStorage.dll", -1
    
End If

fs.copyfile userpath, "U:\db\Timesheet\time_capture_fe.mdb", -1
fs.copyfile "G:\General\database\TimeSheet\deploy\ver.txt", "U:\db\TimeSheet\ver.txt", -1


If fs.FolderExists(TempPath) = False Then
    fs.CreateFolder TempPath
End if

End Sub
'-----------------------------------------------------------------------------------------

Function CheckDeployment() 
Dim BuiltPath
BuiltPath = "U:\db\Timesheet\time_capture_fe.mdb"

If fs.FileExists(BuiltPath) = False Then
    Call CopyUpdate()
End If



End Function
'---------------------------------------------------------------------------------------
sub FireDB

CloseCmdWindow()
dim PathToMDE
PathToMDE = "U:\db\Timesheet\time_capture_fe.mdb"

Set acApp=CreateObject("Access.Application")
acApp.usercontrol=true
acApp.DoCmd.RunCommand (10) 'accmdappmaximize
acApp.DoCmd.Hourglass True


'acApp.AutomationSecurity=1  ' low
acApp.OpenCurrentDatabase PathToMDE
acApp.DoCmd.Hourglass false
Set acApp=Nothing
Set fs = nothing

end sub

'-------------------------------------------------------------
sub OpenCmdWindow()
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe"
WScript.Sleep 10
WshShell.AppActivate "c:\windows\system32\cmd.exe"
WScript.Sleep 100
WshShell.SendKeys "Starting....wait patiently...."


end sub

 '------------------------------------------------------------
sub CloseCmdWindow()
dim oshell
dim oWmg
dim strWndprs
dim objQResult

WScript.Sleep 100

Set oShell = CreateObject("WScript.Shell") 
Set oWmg = GetObject("winmgmts:") 

strWndprs = "select * from Win32_Process where name='cmd.exe'" 
Set objQResult = oWmg.Execquery(strWndprs) 

For Each objProcess In objQResult 

intReturn = objProcess.Terminate(1) 

Next



'WshShell.AppActivate "c:\windows\system32\cmd.exe"
'WScript.Sleep 100
'WshShell.SendKeys "{enter}"
' WshShell.SendKeys "exit"
' WshShell.SendKeys "{enter}"
end sub

'------------------------------------------------------------
Private sub KillBad()

If fs.FileExists("U:\db\Timesheet\time_capture_fe.mdb_Backup.mdb") Then
    fs.DeleteFile "U:\db\Timesheet\time_capture_fe.mdb_Backup.mdb", True
end if

If fs.FileExists("U:\db\Timesheet\time_capture_fe.mdb") Then
    fs.DeleteFile "U:\db\Timesheet\time_capture_fe.mdb", True
end if

If fs.FileExists("U:\db\Timesheet\time_capture_fe.ldb") Then
    fs.DeleteFile "U:\db\Timesheet\time_capture_fe.ldb", True
end if



end sub

Open in new window

Avatar of Nick67
Nick67
Flag of Canada image

This sub opens the command window

sub OpenCmdWindow()
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe"
WScript.Sleep 10
WshShell.AppActivate "c:\windows\system32\cmd.exe"
WScript.Sleep 100
WshShell.SendKeys "Starting....wait patiently...."


end sub


It's only purpose was to provide some visual feedback to the user that the process was going
Line 18 opens it ---> OpenCmdWindow()
Line 108 closes it ---> CloseCmdWindow()
Comment that stuff out and that part is golden
<2nd question:  I have a mixed environment of Access 2000, 2007 and soon to be 2010.
Access 2000 starts up pretty quickly but I noticed that Access 2007 opens to main page ("Getting Started with Microsoft Office Access") and then goes into the database.  Is there any way to prevent that from showing... ?>

That's tougher
Conceivably at line 113 you could put in
acApp.Visible = false
That would hide things
You'd need something in the app's autoexec or initial form's load to unhide it,  but it should be doable
<This will not run with the Access2007 runtime version. >
It's doable.
Have a look for the header Automating Access Runtime a quarter of the way down here
http://support.microsoft.com/kb/317113
http://support.microsoft.com/kb/295179/EN-US
<The Access Runtime must be started with a database. Because of this requirement, if you want to automate the Access Runtime, you must start the Msaccess.exe and specify a database to open. After you use GetObject to retrieve the Application object, you can proceed with automating the Access Runtime. If you try to automate the Access Runtime with the New keyword or with CreateObject, you will receive an error message >

So this will have to change
Set acApp=CreateObject("Access.Application")

However, since it is just firing the db
dim PathToMDE
PathToMDE = "U:\db\Timesheet\time_capture_fe.mdb"

Set acApp=CreateObject("Access.Application")
acApp.usercontrol=true
acApp.DoCmd.RunCommand (10) 'accmdappmaximize
acApp.DoCmd.Hourglass True
'acApp.AutomationSecurity=1  ' low
acApp.OpenCurrentDatabase PathToMDE
acApp.DoCmd.Hourglass false
Set acApp=Nothing

It could conceivably be preceeded with a shell command
Shell "WhateverThePathToTheRuntimeIs\MsAccess.exe" & chr(34) & PathToMDE & Chr(34)
and changed to
Set acApp=GetObject("Access.Application")
Avatar of snyperj

ASKER

Good stuff... I will check it all out when I get in the office tomorrow.  Thanks for the help.  

Any idea on what I could put in the form load event of my initial form that WOULD unhide Access?

"That's tougher
Conceivably at line 113 you could put in
acApp.Visible = false
That would hide things
You'd need something in the app's autoexec or initial form's load to unhide it,  but it should be doable"

Should be as simple as Application.Visible = true
Avatar of snyperj

ASKER

ok, I will try that as well.
Avatar of snyperj

ASKER


"That's tougher
Conceivably at line 113 you could put in
acApp.Visible = false
That would hide things
You'd need something in the app's autoexec or initial form's load to unhide it,  but it should be doable"




I changed the .vbs file as shown below, but the acApp.visible seems to do nothing?  The db still opens as it did before?

Set acApp=CreateObject("Access.Application")
acApp.Visible = False
acApp.usercontrol=true
acApp.DoCmd.RunCommand (10) 'accmdappmaximize
acApp.DoCmd.Hourglass True
ASKER CERTIFIED SOLUTION
Avatar of Nick67
Nick67
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snyperj

ASKER

Thanks.  I haven't tried the runtime version yet, as it is a lesser priority, but I think this will work for what I am trying to do!  Great work Nick67.
You're welcome!
Avatar of snyperj

ASKER

Help.... I found out late Friday that some users will start using the runtime on Monday.  I am having some trouble with that version of the script.  Followup posted here: https://www.experts-exchange.com/questions/27326491/Using-vbs-to-open-a-database-using-the-Access-Runtime.html