Use Value in Word calculated with VBA in Access - ms-access

I've to use a Microsoft Access Database to create different bulk letters in Microsoft Office Word. This works just fine in most cases but it is somehow not possible to use a View (which is defined in Access) in Word as long as the source for data contains a column that is calculated by VBA code in the Access Database. Ah, and I need exactly this calculated value to put it into a Microsoft Office Word Field.
There is unfortunately no way to do this calculation in SQL so I need a solution how I can use those Views as the source in MS Word.
I found just one way yet: Export the View from Access into a Excel Worksheet and use this as the source in Word. As you can think this is very unusable :-(.
(We use Microsoft Office 2003)
Cheers,
Gregor

Try using an Access "Make Table" query. The resulting table will have all the values pre-calculated, and Word won't have a problem reading it.
This is a lot like the suggestion to use a text file, but without the extra mess of making the user generate a text file.

The solution is to use some access word merge code that outputs the query as a text file and then launches the word template and points the template to that intermediate text file.
There are many advantages to the above approach. For one, you don't let word attached to ms-access, so the whole approach is more stable (one application if it freezes up will not affect the other as easy). If you using sql server, or even a workgroup secured access database, it don't matter because the access code is producing that intermediate file. So, even for SQL server, Oracle, MySql etc the word merge will continue to work since we producing a intermediate text file. So, the same merge system works for JET, MySql, Oracle, SQL server, and things will work REGARDLESS of the security settngs on the database.
Also using a intermediate file also means you don't have to resort to some bookmark example which usually means you have to write new code for every merge (that makes no sense!). And, bookmarks are hard to see and insert into the word document.
Another bonus here is word users can continue to use their training courses and teaching and books and on how to setup a word merge document. Another advantage to using merge fields is they allow live preview of the data during editing and composing of the word template document. And, the final resulting merge document does not have any special codes or fields in it.
I have a working sample here that allows you to word enable any form with ONE line of code. This Super easy word merge system then takes over.
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html
Just scroll down in above until you reach the Super Easy Word merge.
The above will allow your VBA expressions in your query also to be used in the word merge.

Related

How to Get Rid of UNUSED Queries in MS ACCESS

I have reviewed the previous Questions and haven't found the answer to the following question,
Is there a Database Tool available in MS Access to run and identify the Queries that are NOT Bring used as a part of my database. We have lots of Queries that are no longer used and I need to clean the database and get rid of these Queries.
Access does have a built in “dependency” feature. The result is a VERY nice tree-view of those dependencies, and you can even launch such objects using that treeview of your application to “navigate” the application so to speak.
The option is found under database tools and is appropriately called Object Dependencies.
The result looks like this:
While you don't want to use auto correct, this feature will force on track changes. If this is a large application, then on first run a significant delay will occur. After that, the results can be viewed instantly. So, most developers still turn off track name autocorrect (often referred to track auto destroy). However, the track auto correct is required for this feature.
And, unfortunately, you have to go query by query, but at least it will display dependences for each query - (forms, or reports). However, VBA code that creates SQL on the fly and uses such queries? Well, it will not catch that case. So, at the end of the day, deleting a query may well still be used in code, and if that code creates SQL on the fly (as at LOT of VBA code does, then you can never really be sure that the query is not not used some place in the application.
So, the dependency checker can easy determine if another query, another form/sub form, or report uses that query. So dependency checker does a rather nice job.
However, VBA code is a different matter, and how VBA code runs and does things cannot be determined until such time code is actually run. In effect, a dependency checker would have to actually run the VBA code, and even then, sometimes code will make several choices as to which query to run, or use - and that is determined by code. I suppose that you could do a quick "search", since a search is global for VBA (all code in modules, reports and forms can be searched). This would find most uses of the query, but not in all cases since as noted VBA code often can and does create sql on the fly.
I have a vague recollection part of Access Analyzer from FMS Inc has this functionality built in.
Failing that, I can see 2 options that may work.
Firstly, you could use the inbuilt Database Documenter. This creates a report that you can export to Excel. You would then need to import this into the database, and write some code that loops the queries to see if they appear in this table;
Alternatively, you could use the undocumented "SaveAsText" feature to loop all Forms/Reports/Macros/Modules in your database, as well as looping the Querydefs and saving their SQL into a text file. You would then write some VBA to loop the queries, open each of the text files and check for the existence of the query.
Either way, rather than just deleting any unused queries, rename then to something like "old_Query", and leave them for a month or so in the database just in case!!
Regards,

Where are the MS Access tables I have shortcuts to?

I have a MS Access 2013 file that I am using. There are two possibly related concerns. For some context, this is an MS Access 2013 file with some forms and some tables and a bit of VBA for the logic of how those two interact. For versioning, the file has been copied and pasted with a datestamp on it for the newer version.
The first concern is that all the file sizes for the various files is exactly the same, even though data has been added and some changes to the forms were made.
The second concern is that when I right click on a table and go to table properties, it says "Shortcut to Table (Local): table_name" where table_name is the name of the table. It appears that this is a shortcut to a table somewhere, but I'm not sure where. The forms are also shortcuts to forms, but I don't see the destination form in my file anywhere, even after unhiding system objects. My questions regarding this are: how did this happen (I was assuming it had something to do with the fact that I copied and pasted the file) and where is the file that these are a shortcut to?
Everything seems to work fine, but I'm concerned that if one of the legacy files gets removed that I might lose some data. Is my data being stored within this file, or did it get split somehow and the data is being stored in a different file somewhere? I just want to have a better grasp of what exactly is going on.
I feel like I have a good handle on the SQL and a pretty good grasp of the VBA, but the MS Access specific nuances are something I'm still gaining familiarity with.
Well, it seems it was as simple as changing the view in your navigation pane to something else than custom!

Access - Linked Excel Sheet query

I am currently working on a database which will bring a number of excel sheets together. I have created a link between the ones in which I need and set up relationships in Access.
I have first-year degree experience of Microsoft software packages. I am not going to move from Excel to Access as other team members are more comfortable using it. However running things like reports, creating forms and querying data can be easier in Access.
The Problem:
I am trying to query data from a linked spreadsheet and it sometimes works and sometimes doesn't. Often more than none my queries return blank when I know they shouldn't.
Is this something to do with the table being linked and not an access table?
Please see an example query that I have set up
Thank you in advance.
If I assume that Status On is a Date field then your criteria is treating this as text, and this expression:
Like "*/*/2013"
may cause unexpected return results, depending particularly on the default Date format of Excel. Use the criteria:
Year([Status On])=2013
which will be much more reliable, not depending on the formatting of the date, purely on the fact that it is a recognisable date.
I don't usually have issues linking to Excel files unless:
The file is Open
The Excel files has links to other files or macros
It is corrupted in some way.
If you are linking to an Excel file then it, ideally, should be a very simple file with, preferably, no other content than a single table of data.

Advice about storing searchable documents with tables and images in MS Access Database

I have a huge MS Word file I use for personal notes but I want it to be more flexible. The file is made from short articles (600 words) with date, title, sometimes a table or some images. I came up with the idea of separating the single articles an put them in Access, to extract them from the database with queries, add tags, sort chronologically.
One big question is: which format should I use? I tried Access 2010 Rich Text Edit but it doesn't show tables, and I don't know where to store images. My idea is to store images outside the file.
Another thing I tried is to store the files as HTML in the database directory, but when I try to add some interface functionality I encounter problems with the most trivial things, like making VBA open the associated file. I don't like storing outside Access also because I don't have full-text search.
The primary requisite for this application is that it must not be cumbersome: it's a prototype I want to use to see if my model of storing notes works, so I don't want to spend a month programming an user interface, and if I note any defect at runtime I must be able to switch to design mode and fix it in minutes. If I want to write something, i don't have to worry about HTML syntax but I want to be able to add some simple table or image.
What I finally search is a HTML viewer in Access interface that receives an HTML string (composed by a query) and displays it.
At this moment I'm considering to remain with my MS Word file because switching seems too complex, although I don't like the sequentiality of articles and the hierarchy of chapters/subchapters, which made me think about this Idea.
The answer to all those problems was Evernote, which is like a Wiki you can edit quickly also from a smartphone, with or without an internet connection, which syncs to a master version on an Evernote server and without the constraint of having to invent a title for every page/idea.
If I had a huge Word document like yours, I'd probably split it into individual files and use something like dtSearch.

Search for field references within a Microsoft Access "application"

I have inherited a MS Access "application" and would like to trace all references to one of the fields.
Is there a way to search for the field (all google hits are for querying the table).
NOTE: I am not looking for any SQL help, I'd like something like the Visual Studio right-click -> find all references type thing.
Go to Tools > Analyze > Documenter
"Select All" items in all categories
Under Options, ensure "code" is checked (should be default)
Run the Documenter report
Export into .rtf or other text format
Search on your field name
This is a good method because it is fast, free, and complete.
Aliases are exposed, in all their variety:
Standard SQL ALIAS in a query.
Use of the Caption or Description property of a table field.
It catches intersections of Access objects and VBA:
a user function in VBA that is called from a query object.
Use in VBA of the value from a control's Tag property.
Some Extra Tips:
If the Documenter seems to have provided everything except the object names, then it's having trouble coping with a long file path. Relocate your work closer to the C Drive so the file path is shorter, then run the Documenter again.
Of course if the database has links to outside data, you must deal with those! If it's an Access database, you can combine the reports into one.
The Access Documenter won't reveal the Object Description, as accessed through the Navigation Pane. The Object Description allows you to attach a bit of text to an object. It was once handy for providing design comments, but since version 2007 it is practically useless. Honestly I wouldn't worry about it, as it's naturally fallen out of use; but its omission from the Documenter is silly and sad.
You might also try the free add-in "Access Dependency Checker".
See the Scan and replace utilities section at the Microsoft Access third party utilities, products, tools, modules, etc. page at my website.
Find and Replace is my preferred utility and it's quite inexpensive. There's a free limited version that works too. I've been using this tool for more than a decade. The author has also added some of my suggestions.
If you want a complete tool documenting all fields, etc, etc then you want FMS Inc's Total Access Analyzer 2007
In my AccdbMerge utility there is a Find tool can search for a text across all loaded object definitions. Even though this is a diff&merge tool, this feature will work even if you will open only one file, and it is available in the free version which will search in tables, queries, macros, forms, reports and modules.
You can also do this without any external tools. MS Access has an option to show all references. You can do this by reight-clicking a table and choose the corresponding menu option.
However, some people have bad experiences with this option so the best thing to do might be to make a copy of the database and turn on the option there. (or just turn it off after you have the results you need).