Solved

Need some additional help with this script to update front ends

Posted on 2011-09-22
11
313 Views
Last Modified: 2012-05-12
Nick67 was gracious to share a method to automatically update front ends in this post:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_27319609.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

0
Comment
Question by:snyperj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 36584013
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
0
 
LVL 26

Expert Comment

by:Nick67
ID: 36584044
<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
0
 
LVL 26

Expert Comment

by:Nick67
ID: 36584095
<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")
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:snyperj
ID: 36584404
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"

0
 
LVL 26

Expert Comment

by:Nick67
ID: 36584414
Should be as simple as Application.Visible = true
0
 

Author Comment

by:snyperj
ID: 36584418
ok, I will try that as well.
0
 

Author Comment

by:snyperj
ID: 36586529

"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
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 36588115
Usercontrol = true overrides visible
http://msdn.microsoft.com/en-us/library/aa663049(v=office.11).aspx
I also have some popup modal messages that make my app error if I try to keep it hidden

You can try pushing these two line farther down into the FireDB() sub
The sleep command is in milliseconds
WScript.Sleep 1000
acApp.usercontrol=true

You can try leaving the usercontrol = true out of the script and put it in the app's autoexec, too

But for me, that can't fly because of the modal message box I have

YMMV
0
 

Author Closing Comment

by:snyperj
ID: 36588562
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.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 36588589
You're welcome!
0
 

Author Comment

by:snyperj
ID: 36595285
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: http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_27326491.html
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question