Access.2007.VBA.Bibl..

(John Hannent) #1
ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit

End Sub

In the cmdInputDocsPath_Clickevent procedure, the GetInputDocsPath()function is
used to get the saved Input Documents path value from tblInfo (if there is one); otherwise the
default Documents folder is opened. The user can select another path, or accept the default path;
the value selected from the dialog is saved to the txtInputDocsPath textbox on the form, which is
bound to the InputDocsPath field in tblInfo. The cmdOutputDocsPath_Clickevent procedure
stores the selected template path to txtOutputDocsPath, which is stored in the OutputDocsPath
field in tblInfo.

I use a tblInfo table in most of my databases to store data that is needed throughout the
database, such as path information. Although you can use global variables for this pur-
pose, they won’t persist from one session to another, and it isn’t easy to examine their values, so I
prefer to store these values in a table.

The custom Input and Output Documents paths stored in tblInfo are picked up wherever needed
in the database, using the GetInputDocsPath()and GetOutputDocsPath()functions,
listed next:

Public Function GetInputDocsPath() As String

On Error GoTo ErrorHandler

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(“tblInfo”)
rst.MoveFirst
strPath = Nz(rst![InputDocsPath])

Add a terminating backslash, if the path doesn’t have one.

If Len(strPath) > 1 And Right(strPath, 1) <> “\” Then
GetInputDocsPath = strPath & “\”
Else
GetInputDocsPath = strPath
End If
rst.Close

ErrorHandlerExit:
Exit Function

ErrorHandler:
MsgBox “Error No: “ & Err.Number & “; Description: “ & _
Err.Description
Resume ErrorHandlerExit

NOTENOTE


Working with Files and Folders 9

Free download pdf