This VB code snippet has been updating an Access database with user-level security for quite some time, but bombed over the weekend. It is based on another posting to Tek-Tips some time back.
Another automated process left two other Access databases open on the same computer. The third database (referenced below) opened properly but the code following the Set accObj command tried to run on one of the other open databases instead of the one it just opened.
How can I force it to work with the database I just opened, or alternately close the other databases automatically?
Dim accObj As Access.application
------------------------------------------------------
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /excl /user " & user & _
" /pwd " & password & " /wrkgrp " & Chr(34) & workgroup &
Chr(34), vbMinimizedFocus)
Set accObj = GetObject(, "Access.Application")
---------------
'Code tried to do update on the wrong database instead of
'the one just opened
--------
DoCmd.SetWarnings False
DoCmd.CopyObject "", "EmplDataBackup", acTable, "EMPLDATA"
DoCmd.RunSQL "Delete *.* from EMPLDATA", 0
DoCmd.TransferText acImportFixed, "EMPLDATA Import Specification", "EmplDATA", "\\mes\dpts\infsys\monarch\Pos\EmplData.txt", False, ""
DoCmd.SetWarnings True
Debug.Print "Done: " & Now()
accObj.CloseCurrentDatabase
accObj.Quit
Set accObj = Nothing
---------------------------------------
The customer may not always be right, but the customer is ALWAYS the customer.
Another automated process left two other Access databases open on the same computer. The third database (referenced below) opened properly but the code following the Set accObj command tried to run on one of the other open databases instead of the one it just opened.
How can I force it to work with the database I just opened, or alternately close the other databases automatically?
Dim accObj As Access.application
------------------------------------------------------
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /excl /user " & user & _
" /pwd " & password & " /wrkgrp " & Chr(34) & workgroup &
Chr(34), vbMinimizedFocus)
Set accObj = GetObject(, "Access.Application")
---------------
'Code tried to do update on the wrong database instead of
'the one just opened
--------
DoCmd.SetWarnings False
DoCmd.CopyObject "", "EmplDataBackup", acTable, "EMPLDATA"
DoCmd.RunSQL "Delete *.* from EMPLDATA", 0
DoCmd.TransferText acImportFixed, "EMPLDATA Import Specification", "EmplDATA", "\\mes\dpts\infsys\monarch\Pos\EmplData.txt", False, ""
DoCmd.SetWarnings True
Debug.Print "Done: " & Now()
accObj.CloseCurrentDatabase
accObj.Quit
Set accObj = Nothing
---------------------------------------
The customer may not always be right, but the customer is ALWAYS the customer.