Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 20th, 2007, 10:54 AM
jmurrayhead's Avatar
jmurrayhead jmurrayhead is online now
The Drunken Moderator
ASP Free God 17th Plane (13000 - 13499 posts)
 
Join Date: Feb 2004
Location: Reston, VA, USA
Posts: 13,072 jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)jmurrayhead User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 82412 Folding Title: Advanced FolderFolding Points: 82412 Folding Title: Advanced FolderFolding Points: 82412 Folding Title: Advanced FolderFolding Points: 82412 Folding Title: Advanced FolderFolding Points: 82412 Folding Title: Advanced Folder
Time spent in forums: 3 Months 6 Days 17 h 33 m 48 sec
Reputation Power: 1580
Facebook
VBA - Update Access Application Closes/Re-Opens New File

Thanks to the help of Don and lewy for this script. This script allows you to close your current open Microsoft Access database and then re-open it. I use this when I change some database settings and need the database to close and reload. You may find this script useful for other things as well.

First, create reload.vbs file:
Code:
 
' Update ONE to the next version.

' Script Version 5/31/2006 


Dim WSHShell
Dim appAccess 				' Current Access application window
Dim fso 				' FileSystem object used to access files
Dim DesktopPath 			' Desktop folder, where shortcut is placed

const iButtonTypeOK = 0			' Popup controls
const iIconTypeStopMark = 16
const iIconTypeQuestionMark = 32
const iIconTypeExclamationMark = 48
const iIconTypeInformationMark = 64
dim intButton 
const iOKButtonClicked = 1
const iButtonsNotClicked = -1

const strONEfilename = "c:\program files\oicwcms\one"
const strONEfolder = "\\db1\one"

<font color="Red">Set WSHShell = WScript.CreateObject("WScript.Shell")</font>
DesktopPath = WSHShell.SpecialFolders("Desktop")
<font color="Red">Set fso = createobject("Scripting.FilesystemObject")</font>


' Warn the user that updating is about to occur.
' (A 10 second delay is added.  With a slow network connection, somehow this 
' helps to avoid the automatic update from being launched a second time.)

While intButton <> iButtonsNotClicked 

intButton = WSHShell.Popup( "W A I T !  Don't click the button!" & vbCrLf  & vbCrLf & "ONE is about to be automatically updated.  Please wait while the new version is loaded--then you will see another alert dialog.",10,"Automatic Update of ONE",iButtonTypeOK + iIconTypeStopMark )

Wend


' <font color="Red">First stop the current Access program</font>, then copy files from the 
' ONE folder to the C: drive, <font color="Red">then launch the new program in the same
' application window</font>.

on error resume next
' Detect if ONE is running (from the proper folder) by an indirect method:
' If the LDB file cannot be deleted then the MDB file is probably opened.
' Trap the error accordingly.
fso.DeleteFile strONEfilename & ".ldb" 

if Err.Number = 70 then 
    ' LDB file cannot be deleted, so ONE is running as expected.
    on error goto 0

    ' <font color="Red">Close down the instance that called this script</font>
    Set appAccess = Wscript.getObject(strONEfilename & ".mdb")
    appAccess.CloseCurrentDatabase 

    ' Update ONE
    on error resume next
    fso.CopyFile strONEfolder & "\one.mdb", strONEfilename & ".mdb"
    fso.CopyFile strONEfolder & "\one.hlp", strONEfilename & ".hlp"
    fso.CopyFile strONEfolder & "\one.lnk", DesktopPath & "\one.lnk"

    if Err.Number = 0 then

        ' Announce that ONE has been successfully updated

        WSHShell.Popup "Your ONE program has been updated." & vbCrLf & vbCrLf & "Click the button to launch ONE.",0,"Automatic Update of ONE",iButtonTypeOK + iIconTypeInformationMark 

        ' <font color="Red">Launch the updated program in the same Access window</font>

        appAccess.Opencurrentdatabase strONEfilename & ".mdb"

        ' Done !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    !!!!

    elseif Err.Number = 76 then

        ' The ONE file server folder is not available.
        ' Leave Access open with no program running.

        WSHShell.Popup "The copy script cannot update your program, probably due to an intermittent network problem; it failed with error " & err.number & ": " & err.description & "  !!!",0,"Automatic Update Failure", iButtonTypeOK + iIconTypeInformationMark

        ' Done !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    !!!!

    else

        ' Unexpected error

        WSHShell.Popup "The copy script failed with error " & err.number & ": " & err.description & "  !!!  Please report this error and do not continue using the program !!!",0,"Automatic Update Failure", iButtonTypeOK + iIconTypeExclamationMark 

        ' Done !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    !!!!

    end if

else

    'Perhaps the script was launched in another way, 
    'or the user has already closed ONE.

    WSHShell.Popup "The copy script failed with error " & err.number & ": " & err.description & "  !!!  If this happens again then please report this error and do not continue using the program !!!",0,"Automatic Update Failure", iButtonTypeOK + iIconTypeExclamationMark 

end if  


To call this from within your Access file, use following function:

Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Sub Test()
'Open file
ShellExecute 0, "Open", "H:\reload.vbs", "", "", 1
End Sub


To refer to the original thread, click here
__________________
jmurrayhead

Did I help you out? Make me popular by clicking the icon!

New Members:Proper way to post a question

Powered by ASP.Net

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > VBA - Update Access Application Closes/Re-Opens New File


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway