I have the following vba-code in an MS-Access97-frontend which opens a word-document stored on a server:
Call Shell("winword ""\\Fileserver\Contabilita\Crucial deadlines\Bonifico97.doc""", 1)
The document is a merge-document (getting data from a query and populates the document from the data retrieved)
Now, I have put the database-frontend on another computer (still using MS-Access 97 but with MS-Word 2003 installed on the PC - MS-Access 97 is still working nicely since it was installed in a different directory) but now when above code, using call shell, is being executed, I always get "Document not found". If I launch above shell command in Start/execute, the document is being opened correctly.
What could be the problem? The file-path? Did any anything change in VBA 97 and VBA2003 what regards file-paths? I am aware of the fact that there is a folder in the file-path with a space but it works nicely on the PC with office97 installed.
I would appreciate any help I can get. Thank you.
You will need to use the full path for Word.
Alternatives to using SHELL with the full path specified for Word would be:
Application.FollowHyperlink
ShellExecute
In either case, you'd be opening the file with the application associated with the file association of the file you're opening. The only reason to stick with Shell() is if you're using the PID returned by the Shell() function to control the application after it's run. But your original code used Call Shell... so that wasn't an issue.
Related
Hi there hopefully there is a fix for this but I my ms access program crashed before it could finish a clean up of the data. Its now hit its 2GB maximum and wont open anyone know what do here? I just need it to drop all the data in the columns the thing of value are the queries and what order they are in.
Just get the error Cannot Open database''. It may not be a database that your application recognises, or the file may be corrupt. It gives me that twice.
its in an .accdb format so that shouldnt be a reading issue
Cheers.
Try running a compact and repair directly from the DAO database engine without opening the file in Access
You can use the following code from any VBA-enabled application or a VBScript file (it's designed for VBScript files, but you have to match bitness with your Access application, see this post, but should run fine from Excel as well)
Dim wShell, oExec, sFileSelected
Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE><script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
CreateObject("DAO.DBEngine.120").CompactDatabase sFileSelected, Left(sFileSelected, Len(sFileSelected) - 6) & "Compacted.accdb"
That should copy over everything from your corrupt database while compacting it. It creates a new file, with your current filename and Compacted appended to it.
5893.1
Hi all,
I have searched and got answers for my questions many times from this forum. However, I now have a question that I don't think anyone has asked before.
We use Windows DOS batch to compact MS Access 2010 DB files everyday. It seems Access does not pass any return code to DOS. So my question is: Is there a way to tell whether the compacting is successful or not from within the batch?
We use Win XP/7 machines for development, and Windows Server 2008 for production. We are running MS Access 2010.
The DOS batch has a line like "D:\Microsoft Office\Office14\msaccess.exe" %DBLoc%%BkupFile% /compact %DBLoc%%DBFile%
Any help is much appreciated.
Doesn't appear that there is a return code.
However, one time-tested technique is to pipe the output from the command to a text file and then test the contents of the text file. That way, if there's an error message printed at least you'll be able to catch that.
eg. add ' > test.txt' to the end of the command line.
You'd have to check on the available command shell tools to read the text.
You may also have to specifically redirect the error output separately from the command output. see here for redirection info : http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true
Edit: to head off the next question, some links on detecting the failure message in the text file
http://ss64.com/nt/findstr.html
How to set variable with the result of findstr
I followed the suggestion by Cody Gray about halfway down the page in this thread but I'm having no luck.
Unless I'm missing something, this is supposed to allow me to navigate from Access, using the Windows API Dialog Box, to the relevant folder and open a file, no? I'm trying to open a Word doc which has a Mail Merge coming back to the same Access Db. I needed the dialog because there are multiple files that may be selected at different times.
I added all the suggested code and while the process runs without error, when I get to the final step, the selected file doesn't open. Nothing happens.
I realize this is not much help without an error message. Any thoughts nonetheless?
As I understand the situation, you have code which uses a string variable named strFileToOpen to hold the path to a Ms Word document. And now you want to open that file in Word.
You can use the FollowHyperlink method.
Application.FollowHyperlink strFileToOpen
Look at the Access help topic for that method. It offers other options you may wish to use.
Also I suggest you look at the help topic for FileDialog Object. It is simpler than the Windows APi method in the code you linked.
We currently have an ASP/SQl Server system, which has an option to send an e-mail to a user. This e-mail contains a hyperlink to another ASP page, which shows a specific database record.
I'm currently working on a resilience version of the system, which is MS Access based. The user's would like to keep the same functionality, and have an e-mail which contains a hyperlink back to the database, opening a specific form and filtering it to a record.
I believe the solution lies somewhere in using Command() to get the parameters from the command line, however I am actually having difficulty currently opening the database itself. The code i'm currently using is:
<a href="C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.exe
H:\Access DB\11th March\Link to DB\Dealer
Startup Admin EU v10.mdb" >
TEST
</a>
I think this should open the Dealer Startup database, however it is failing stating the file cannot be found. If I remove the second step i.e. H:\Access DB etc. the link opens Access, so I am wondering if i'm doing something syntactically incorrect? The file path definitely seems right.
Also would someone be able to give some advice on the use of /c in a hyperlink? The small amount of information I have found seems to suggest it doesn't work but if someone could clarify or give me an example of how to do it I would appreciate it
Thanks,
Chris
I managed to create a solution to this problem. I could not find a direct way to open the Access DB from a hyperlink, however you can hyperlink to a shortcut. The workaround I therefore used was to create a shortcut to the database using the following syntax:
"file path to ms access" "file path to database" /cmd Args
so for example:
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.exe" "C:\Documents and Settings\Database.mdb" /cmd Args
Creating a shortcut to this file path opens the database. I then created an autoexec macro which opened a specified form if the Command() function returned Args. This meant that when opening the database normally you would be taken to the usual form, but when opening from the shortcut you will be taken to a different form.
I then created the e-mail hyperlink to the shortcut.
I have created a batch file to delete browser history for MSIE and kept it on the server-side. When the user clicks on 'delete browser history' hyperlink, I just make him download this file, and the user runs it manually.
You can also do something similar.
I have a scenario where a user who is not on the domain is trying to open a file that is on the network. Trying to determine if the path exists using the Dir() function. Here is what my code looks like...
If Len(Dir("\\xx\xxxxx\Shared\Virtual Machine\_Testing\Update\", vbDirectory)) > 0 Then Return True
I get the Run-Time error Bad file name or number (error number 52).
Yep, dir() on a bad/inaccessible unc causes a runtime error, unlike the behaviour for a local file.
You can either wrap it in an error handler or use the GetFileAttributes API and look for the directory attribute flag (the built in getattr() won't work for this).
For the time-being, if the user doesn't mind mapping a network drive, he could open the file with your code the way it is.
Try below steps.
Restart your machine
After restart, access/open the share path through windows explorer
Provide the network credentials and select the option "remember my
credentials"
Now run/debug your application. it should work!