MS Access VBA
MS Access: Inserting and Deleting Contact Items With VBA
Submitted by johnk on Tue, 12/18/2007 - 00:59.Gripe: VBA syntax is difficult. The object system is a little confusing too. It's just very hard to use. To make things even more difficult, the sample code out there is kind of *weird*. Maybe there's some good reasons for doing things their way, but, it just seems verbose, error prone, and hard to write, to me.
Here's some code that is the start of a library to work with Outlook's folders. It's based on some code samples from the web, refactored into something resembling a library.
The best feature is the function OLGetSubFolder, which returns a MAPI folder object for a given path. Totally useful.
MS Access: Printing the Range of Data on the Page on a Report
Submitted by johnk on Thu, 11/29/2007 - 22:50.I wanted to print a report that indicated the first and last item on each page, just like a dictionary has. You know: "Azeri - Babcock", "Milk - Minder". It makes it easier to flip through printouts.
This is how to do it. It will put the range in the footer. I haven't figured out how to do one in the header, which is what I originally wanted, but found too difficult to do. (There is probably a way.)
First, take your report, and add an unbound field to your report. Rename it to "Range". See the picture below.
Then, set up event handlers for the On Print event of each section. An explanation follows the picture. Here's my code:
Option Compare Database Option Explicit Public FirstRow As String Public CurrentRow As String
MS Access: Logging Messages
Submitted by johnk on Wed, 11/14/2007 - 21:56.Here's some code to help you log messages to a table. First, make a table called tblLog, with at least these columns: Timestamp, User, Computer, Message. (You don't need a primary key.)
Set the default value of Timestamp to NOW().
Copy the following code into a code module.
Also, add a reference to "Active DS Type something or other". It has the active directory functions you need to discover the username.
Function StartUp()
Dim dummy
dummy = LogOpen()
DoCmd.OpenForm "frmHidden", acNormal, , , , acHidden
StartUp = Null
End Function
Function LogOpen()
LogMessage ("User opened database.")
End Function
Function LogClose()
LogMessage ("User closed database.")
End Function
Function LogMessage(Mess As String)MS Access: Application Configuration Settings in Tables
Submitted by johnk on Tue, 11/13/2007 - 18:02.This is a relational way to store application configuration in a table. It uses two tables, so you can store multiple configurations, so that you can use the tool over and over, and still retain the old settings. One table stores configurations, and one stores a since row with the current configuration in use.
Setting values are retrieved from the configuration tables with queries like this:
(SELECT PreRegActivityID FROM Congress7_Config WHERE ID=(SELECT CurrentConfigID FROM Congress7_CurrentConfig))

MS Access: Inserting Blank Rows
Submitted by johnk on Wed, 11/07/2007 - 03:43.This is a way to insert empty or empty-like rows into a list of "seats" that contains not only reservations, but a number saying how many seats a group of people have.
Updating a Combo Box with a Requery
Submitted by johnk on Sat, 11/03/2007 - 13:47.In MS Access, when you want a form containing a foreign key, you typically use a combo box that's populated with data from the foreign table. The underlying field is the fkey's value, but the combo box displays another column from that table that is easier for people to read. For example:
The Foo table has an fkey, PeopleID, that refers to the tblPeople table.
TblPeople has a field, Name, that is the person's name - a human comprehensible value.
The frmFoo form has a combo box that's bound to the PeopleID fkey.
The combo box will populate the PeopleID fkey with a number, but displays the Name field, so it's easy for people to use.
Removing Rows from a Table with Access, for JBlast
Submitted by johnk on Fri, 09/14/2007 - 10:06.The goal is to remove all the bad fax numbers from a JBlast fax list. This applies to any situation where you want to remove one list of data from another list of data. Another way to say it is that you have a full list, and you're trying to remove a sublist from the full list.
The way you do it is by taking the full list, and then doing a JOIN that will add a column that identifies the rows that are present in the sublist. You can do this with a LEFT JOIN. A LEFT JOIN includes all the rows in the left table, in this case, the full list. It matches on a key in the right table, and when there's a match, columns from the right table are included; when there's no match, the columns are set to NULL.
The following image shows a left join in Access.
Novice's Notebook
Submitted by johnk on Wed, 12/13/2006 - 02:16.This is a repository of "novice" articles, written with the intent of driving more traffic to the site, and getting more ad clicks. It's pretty crass, I know, but the information may be very useful. Some of the content is adapted from the diy notes, and other notebooks, which are a bit rougher than these.
Most of these articles are not authoritative, because they're based on what I'm learning, as I'm learning it.

