Access.2007.VBA.Bibl..

(John Hannent) #1
End Function

Public Function GetOutputDocsPath() As String

On Error GoTo ErrorHandler

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

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

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

ErrorHandlerExit:
Exit Function

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

End Function

Figure 9.2 shows the Folder Picker dialog for selecting a custom Output Documents path.

To use the FileDialogobject in your code, you need to set a reference to the Office object
library; that reference is not set by default in a newly created Access 2007 database. Figure 9.3
shows the Office 12.0 reference being checked in the References dialog for the Files and Folders
database.

Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf