Online Book Reader

Home Category

Access Cookbook - Ken Getz [100]

By Root 1971 0

Application.RefreshTitleBar

Exit Sub

HandleErr:

Select Case Err.Number

Case 3270 'Property not found

Set prp = CurrentDb.CreateProperty( _

"AppTitle", dbText, Me.txtNewCaption)

CurrentDb.Properties.Append prp

Case Else

MsgBox _

Err.Number & ": " & Err.Description, , "cmdNewCaption"

End Select

Resume ExitHere

End Sub

To retrieve the titlebar caption when the form opens, we used error handling that assumes the caption is "Microsoft Access" if the AppTitle property hasn't been used to change it:

Private Sub Form_Open(Cancel As Integer)

On Error Resume Next

Me.txtOldCaption = CurrentDb.Properties("AppTitle")

If Err.Number <> 0 Then

Me.txtOldCaption = "Microsoft Access"

End If

End Sub

What are the trade-offs? The Windows API requires less code, runs faster, and works with applications other than Access (if you can get a window handle, you can set the caption). However, the AppTitle property actually persistently sets the database's property, so the next time you load the database, the title is set for you. It takes a bit more work to use the non-API Access method, but it does allow you to preserve the setting for your next session.

One final note: the Windows API allows you to set the caption to be an empty string. You cannot set the Access AppTitle property to be an empty string; Access will reject it. If you want to remove the text from the titlebar altogether, use the API method.

CREATE YOUR OWN SPLASH SCREEN

The Tools → Startup menu does not provide a method by which you can supply your own startup bitmap image. If you want to supply your own bitmap splash screen to use rather than Access's built-in image, you can place a bitmap (*.bmp) file in the same directory as your application with the same name as your application. When you double-click on your MDB file to start it, or create a shortcut that starts it, Access will find your bitmap and use it as your startup splash screen. If you want no splash screen at all, simply create a single-pixel bitmap (use a light color for that single pixel). It will be so small that no one will notice it as Access opens.

4.8. Use the Windows File Open/Save Common Dialogs


Problem


You need to allow users to choose filenames for opening and saving files. You know that Windows supports a common way to get these names. How can you use this mechanism from within Access?

Solution


Not only can you use the common File Open/Save dialogs, but you even have three ways to do it:

You can use the ActiveX control, COMMDLG.OCX, that ships with the some versions of the developer version of Office, and with Visual Basic.

In Access 2002 and later, you can use the FileDialog object.

You can call the Windows API directly.

If you don't have the developer version of Office, or Visual Basic, the first suggestion won't help. In addition, distribution of applications that use the common dialog ActiveX can get complex, because of ActiveX versioning issues. The FileDialog object added in Access 2002 makes it easier to select files, but it's not available in earlier versions. Therefore, this solution shows how to call the Windows API directly and lists all the options you have when using these common dialogs.

Open and run the form frmTestOpenSave from 04-08.MDB. This sample form allows you to set various flags (described later in this solution) and to see the results. You can try both the File Save and File Open common dialogs. Try changing some of the settings and see what happens. Figure 4-16 shows the File Open dialog—with the Read Only checkbox hidden and allowing for multiple selections—displayed in explorer mode (as opposed to the older Program Manager look, which is what Windows will use if you specify the multiselect option by itself ).

Figure 4-16. The sample form, frmTestOpenSave, showing the File Open dialog in use

To use this functionality within your own applications, follow these steps:

Import the module basCommonFile from 04-08.MDB into your own application. This module provides the type and API function declarations you'll need and

Return Main Page Previous Page Next Page

®Online Book Reader