Sunday, April 29, 2012

MS Access to Oracle ODBC Connection

I recently had an adhoc reporting project using MS Access querying Oracle tables via ODBC. Thought I would share the process for anyone that might need it.

Though I could make the connection read/write, for safety and because I didn't need to make any changes to the Oracle data, a read-only connection was made. Here's the basic overview:

Oracle provides a free local client (Instant Client) and ODBC driver that is used for the connection. It can be downloaded from:

It's important to select the correct driver - either 32 or 64 bit. The Oracle documentation doesn't clearly explain but keep in mind that you want the driver version to match your Oracle server version. I used the 32-bit version. After downloading and installing the Oracle "Instant Client" (make sure to download the separate ODBC driver that is part of the Instant Client), you must setup your system PATH and TNS_ADMIN variable as follows:

• In Windows explorer LEFT pane, right click on “My Computer” icon and click “Properties”

• Click “Advanced system settings” tab

• Click Environment variables button:

• In the “System Variables” panel select “Path” variable and click “Edit” button:

• Now find a variable called TNS_ADMIN — it could be in either System or User panel (I chose System so that all users on this PC would have access), if you have no such variable, create it in the User panel by clicking “New”:

• Variable Name: TNS_ADMIN

• Variable Value: C:\InstantClient (or whatever folder you designated in the install above)

• Click Ok

• Now click “Ok” on the Environment Variables screen and click “Ok” on the System Properties window to close it

• Run C:\InstantClient\odbc_install to install the Oracle ODBC driver.

• Run the ODBC Data Source Administrator to configure your connection. Note: The default ODBC
Data Source Administrator is 64-bit so if you are running the 32-bit ODBC driver, you will have to specifically run the above file (on my machine it was found at (C:\Windows\SysWOW64\odbcad32.exe).

• Select “System DSN” and configure as shown:

• Click “Test Connection” to confirm set-up. You will be asked for a TNS Service Name, User ID and password which your Oracle administrator can give you. If all is correct you should see a successful connection message.

Once connected, I was able to design and run all my reports without issue.

MS Access SharePoint Attachment Field

I recently tested a project that is a good candidate for MS Access on Sharepoint. It is an ongoing project keying records daily from scanned images and would require at least 3 keyers daily. The advantages are obvious: ability to work remotely, centralized administration, and flexibility to distribute or redistribute work flow.

I developed forms with needed validation rules for each unique image that we are keying from. Within the table design (and then forms) I included an attachment field. When an attachment field is added to a form, the first image will show. As I will only add one image per record, this works perfectly for our purpose.

For management tools, I designed a separate, client application that links to the Sharepoint lists (tables). I run daily processes and updates from this "management" application. I needed a way to add all new images in a batch process daily. My images arrive as tifs since this is the default and best format on scanning images. However, this format is not "web enabled" and needed to be converted to jpg's to render in the browser. After batch converting the tif's to jpg's, I batch add them to the table with the following two-step vba functions: First, I populate a field in the table (list) with the name of the image (having all new images in a folder):

Public Function PopulateImages()
Dim strFile As String
Dim strFolder As String
Dim strSQL As String

strFolder = "C:\Folder\NewImages\"
strFile = Dir$(strFolder & "*.jpg")

Do While Len(strFile) > 0
strSQL = "INSERT INTO TicketsTbl (ImageName) " & "VALUES(" & Chr$(34) & strFile & Chr$(34) & ")"
CurrentDb.Execute strSQL, dbFailOnError
strFile = Dir$()
End Function

Then I add the attachments:

Sub AddAttachments()
Dim mfile
Set db = CurrentDb
Dim rsTickets As DAO.Recordset

Set rsTickets = db.OpenRecordset("TicketsTbl")

If Not (rsTickets.EOF And rsTickets.BOF) Then
Do Until rsTickets.EOF
Set rsPictures = rsTickets.Fields("Field1").Value
mfile = rsTickets.Fields("ImageName")
mfile = "C:\Folder\1F\" & mfile

rsPictures.Fields("FileData").LoadFromFile mfile


End If

Set rsTickets = Nothing
Set db = Nothing

End Sub

NOTE: I set the process running and checked back later and found that adding 150 jpg attachments took one hour. Not real speedy and an obvious consideration that will make this process unreasonable for some projects.

I have the ability to run counts, do quality control and give feedback to keyers based on the login information that Sharepoint always captures. The built in fields are "SharePointCreatedDate", "Author", "SharePointModifiedDate" and "SharePointEditor." I always add similar fields to my desktop applications but these are included in any SharePoint list.

I found no fully-developed instructions to this process on the web (though I started with a basic outline of the add attachment function from Microsoft) so I'm hopeful that this information will be helpful to some of you. Would love to hear your feedback.