Online Book Reader

Home Category

Access Cookbook - Ken Getz [53]

By Root 1835 0

Else

Me.cmdHelp.Visible = False

End If

If Not IsNull(basInputBox.varXPos) Then

DoCmd.MoveSize basInputBox.varXPos

End If

If Not IsNull(basInputBox.varYPos) Then

DoCmd.MoveSize , basInputBox.varYPos

End If

ExitHere:

Exit Sub

HandleErr:

' Disregard errors.

Resume Next

End Sub

Programmatically accessing online help


If you specify a help file and a context ID when you call acbInputBox, the code will enable a Help button on the form. When you click on that button, Access will load the help file, opened to the appropriate page. How did that all happen? The code attached to the Help button's Click event, shown here, calls the WinHelp API function, giving it a help file name, an action (acbcHELP_CONTEXT, indicating that the code wants to supply a context ID and have that page visible when the file opens), and the context ID you supplied. The following is the code that enables this functionality:

Const acbcHELP_CONTEXT = &H1&

Private Declare Function WinHelp _

Lib "user32" Alias "WinHelpA" _

(ByVal Hwnd As Long, ByVal lpHelpFile As String, _

ByVal wCommand As Long, ByVal dwData As Any) As Long

Private Sub cmdHelp_Click( )

WinHelp Me.hWnd, mvarHelpFile, acbcHELP_CONTEXT, CLng(mvarContext)

End Sub

Every page of a Windows help file can be accessed via the unique context ID that's assigned to it when you build the help file. Unfortunately, this is of use only if you've built the help file yourself or have a list of the context IDs for the various pages. No such list is available for the Access help file; even if it was, you cannot distribute the Access help file with your own applications. If you provide your own help file with your Access application, however, this technique makes it easy to have a help topic available at the click of a button.

Miscellaneous comments


The techniques presented here are not limited to this particular solution. You can use them any time you need to provide a modal dialog that gathers information and then returns that information once you're done with it. Once you've mastered the concepts in the "Creating pop-up forms" section, you will have a technique you can use over and over (for example, to provide a pop-up calendar form or a password input form).

The method we chose for initializing the pop-up form (using module public variables) is not the only method we could have used. Another popular method is to pass information to the form in its OpenArgs property: adding an OpenArgs parameter to the Open Form action allows you to pass information directly to the opening form. In this case, because there were many pieces of information to pass over (and the OpenArgs property is limited to a single string value), we would have had to write treacherous code to parse the string out to retrieve the values. Using the technique we chose, it's just a matter of reading the values from the module where they were declared. Though this may seem a little messy, it's a lot simpler in the long run.

See Also


To learn more about the IsMissing VBA function, search for "IsMissing" in the Access online help. See Recipe 7.6 in Chapter 7 to learn another technique for handling parameters. See Recipe 9.10 in Chapter 9 for another example of creating a reusable form. For more examples that call API functions, see Chapter 11.

2.10. Store the Sizes and Locations of Forms


Problem


Your application uses a number of forms that you can move around the screen. You'd like to store the last location away somewhere so that the forms will appear in the same location the next time you start the application.

Solution


Some Windows applications are "smart" and can save the locations of their windows when they exit. Your application can do this, too, using the system registry. You can store settings when you close a form and read them back the next time you open it.

Open and run the form frmSavePos in 02-10.MDB. Move it around the screen, and perhaps resize it. When you close the form, code attached to the Close event will save its coordinates in the system registry database. When

Return Main Page Previous Page Next Page

®Online Book Reader