MS Access - return code to DOS batch - ms-access

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

Related

View SQL code for job in SQL Server Management Studio

I want to view the SQL code that is executed for a particular job in SQL Server Management Studio.
Specifically, I have a screen that looks like this:
If I double click it I get a screen that looks like this:
That is not really helpful. I want to see the actual code that is running and possibly modify it.
I am a long time developer but new to Windows so please give an answer that uses terminology that I can see on the screen.
[EDIT] If I click the edit button on the first screen I get the same screen as if I double click it. There is a DTSRun command and some jibberish which is not anything I would expect to edit.
[EDIT] I followed these instructions to decode the encrypted command line:
https://blogs.technet.microsoft.com/vipulshah/2007/03/12/how-to-identify-which-dts-package-is-being-called-by-scheduled-job/
Then I could see the command line looks like this:
DTSRun /S "192.168.2.1" /U "sa" /P "changeme" /N "Delete AppErrors"
I then searched the entire computer for a filename that contained AppErrors in the name. I did not find one.
So I am getting closer, but how do I find what that is executing?
There is no SQL code in this job/task, because the task type is "Operating system (CmdExec)", i.e. this is not a SQL query, but starting of Windows executable file. There will be SQL code for step type "Transact-SQL script (T-SQL)":
What you see in you job step, is execution of SSIS package, which is encrypted. For more information about DTSRun command, take a look at this article - SQL Server DTS command line utility.
I almost solved my problem like this:
A.
I followed the instructions here to decode the encrypted command line:
https://blogs.technet.microsoft.com/vipulshah/2007/03/12/how-to-identify-which-dts-package-is-being-called-by-scheduled-job/
Which amounted to:
Copy the DTSRUN line (everything including the DTSRUN)
Open a Windows Command Line window
Paste the DTSRUN line into the CMD window.
To the end of the line, add /!X /!C
/!X = do not execute /!C = copy results onto Windows Clipboard
Run the command
Open Notepad
Click Edit>Paste
that will paste the actual command into Notepad and it will show the name of the package.
B.
I observed that the command line looked like this:
DTSRun /S "192.168.2.1" /U "sa" /P "changeme" /N "Delete AppErrors"
C.
Then I follow the instructions here to find the code:
https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/cc645945(v=sql.105)
which amounted to:
In Object Explorer, expand the Management folder.
Expand the Legacy subfolder.
Expand the Data Transformation Services subfolder to show packages.
D.
I right click on it and choose Open. I get this error:
I should not have to install anything because the person who put this on the machine must have been able to edit it. (this person is completely unavailable so I can't ask him). The reason I need access to it is that we are upgrading the machine.

How to increase VBA error output to diagnose consistent crashing after "File not found" error

Is there a way I can make the application MS Access and VBA more verbose in order to better diagnose errors from the IDE?
I open my MS Access project, I get a message dialog box, titled "Microsoft Visual Basic for Applications" with the message "File not found:" without any path specified. Opening the form file works as expected.
When I go into VBA, I can run some commands from the Immediate window. The following actions will make MS Access crash, showing a messaged box titled "Microsoft Access has stopped working":
Closing the database
Stopping the debugger (it opens being active, trying to load a form)
Selecting text of the procedure I was working on when MS-Access / VBA initially crashed.
This does not answer the question, but it seems the underlying problem has been fixed by deleting the procedure in question, letting MS Access crash and re-opening VBA.
To answer the question in your title: If the error is actually cause by VBA code, you can catch the error (using On Error Goto ...) and provide additional information based on the context of your method (the file you were trying to open, etc.). Unfortunately, there is no magical switch to make the built-in error messages more useful.
To answer the question in your question body: From what you describe, the error is not caused by actual user-supplied VBA code. Instead, your database or its VBA module is corrupt (Access crashing or showing seemingly random errors is a strong sign of that). Repair, compact and decompile your database. It might be worth checking out the VBA references as well, so see if any of those are missing.
can you execute the command resume in the immediate window ? it should send you back to the code line where the file was not found.

"Learn SQL The Hard Way" - How to Setup Properly for Beginner?

I am a beginner attempting to learn SQL with Zed Shaw's "How to Learn SQL the Hard Way"
In excercise 0: The Set up, he states:
Then, look to see that the test.db file is there. If that works then you're all set.
But when I run the command,
sqlite> create table test (id);
sqlite> .quit
the execution runs, but it doesn't create a test.db file. I looked in the same folder as where the sqlite3.exe file is and I see nothing.
I attempt to see if I can continue without this step, then - In his next exercise, "Excercise 1: Creating Tables":
I input his commands, but when attempting to run sqlite3 ex1.db < ex1.sql, it gives me an error.
I even tried putting the create table command and saving it as a '.sql' file into the same folder as sqlite3.exe.
How can I set this environment up properly? Can someone explain this on an "easy to grasp" level? Any response is appreciated**
Edit 1
I'm not exactly sure how Zed Shaw how he wants his learners to use SQLite 3, Maybe I can go into some research but I just don't understand why he leaves such a large gap of assumption that everyone knows what to do for the set up process...
I had this exact problem. I am using windows 7.
From this website: http://www.sqlite.org/download.html
I used the:
"sqlite-tools-win32-x86-3130000.zip
(1.51 MiB) A bundle of command-line tools for managing SQLite..."
under the "Precompiled Binaries for Windows" heading.
My helper directed me to open the file named "sqlite3" after I'd extracted the files from the zip file. It brought up a black window, in the command line style, showing some text, and then the familiar sqlite> prompt.
Then he had me input:" .save data_base_name.db " (I chose to have my database be named 'thedatabase'.)
which created a file in the same folder as the sqlite3 file, called "data_base_name" as a "Data Base File".
That's where I'm at so far, I'll post updates as I have them.

MS-Access compile options

Is there a compiler option in ms-access (2003) that requires all vba code to compile before allowing any code to run? I'd like to be able to turn it off. I've tried the unchecking the 'Require Variable Declaration' and 'Auto Syntax Check' options, but no result.
Background information
I've just been given an ms-access database that runs fine on their machine but will not run on my machine. I get this error message on startup:
"The expression On Open you entered as the event property setting produced the following error: Method or data member not found"
This is caused by vba compilation errors in what looks like redundant code. Interestingly the code doesn't compile on either machine, but on their machine it database is usable on my machine it isn't! I assume its something simple like a compiler option, except I can't find it!
(Before anyone mentions it I know that the real solution to the problem is to fix/remove the bad code)
Code will run in MS Access without all code compiling, however, On Open is a form property that runs code when the form is opened, so the code in that event will be compiled and run when the form opens. I have encountered this error before when a version of Access is run on a PC that has two versions installed (specifically, <2007 and >=2007). For me, the solution was to choose Repair from the Help menu.
Access has a /decompile command line switch. See the accepted answer to this StackOverflow question.

microsoft office/access - problem with filepath using call shell from vba

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.