Create a Replacement for Access’s InputBox

Problem

You’d like to be able to use Access’s InputBox function in your applications, but it’s so ugly! There doesn’t appear to be any way to modify the way it looks, so you’d like to replace it with a standardized input form of your own. You’d also like to be able to call into your help file with a Help button on the input box.

Solution

The dialog you see when you run Access’s InputBox function is just a form, like any other form, except that it’s built into Access. You can create your own form, open it as a dialog form, and have it look any way you like. This solution demonstrates a technique you can use in many situations: creating a pop-up form that waits for input and, once it’s done, allows the caller to retrieve the information gathered on the form. In this case, you’ll call the acbInputBox function instead of InputBox, but the results will be the same.

Load and run frmTestInputBox from 02-09.MDB. This sample form gathers information and then calls the acbInputBox function to display the replacement input form. Once you’re done with the input form, choose OK (to return the text you’ve entered) or Cancel (to discard it). The sample form will pop up a message box with the text you entered. Figure 2-16 shows the two forms at work.

Use frmTestInputBox to test the replacement input box

Figure 2-16. Use frmTestInputBox to test the replacement input box

Follow these steps to include this functionality ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.