Visit our new web pages

We have launched a new extended set of web pages at www.alvechurchdata.co.uk. These old pages will stay on the server because people still have links to them but they will not be updated.

The new version of this page is at www.alvechurchdata.co.uk/hints-and-tips/accconfirm.html.

Wrapping the call to MsgBox


The MsgBox() function lets you display a standard Windows dialog to get a Yes/No answer from the user. The dialog is reliable and familiar but the call to this function can be a bit verbose:

If MsgBox ("Are you sure", _
  vbQuestion + vbYesNo, _
  "Delete record") = vbYes Then...

This call then gives you a return value of 6 or 7 so you need to write further code to determine whether the user said 'Yes' or 'No'.

You can make life a lot easier by writing a function to wrap the MsgBox call. We use a function named "Confirm" which takes the text and title as parameters and converts the numeric return from MsgeBox into True or False.

The body of the function is very simple:

Public Function Confirm (strMessage As String, strTitle As String) As Boolean
Dim bytChoice As Byte

bytChoice = Msgbox(strMessage, _
  vbQuestion + vbYesNo, _
  tcTitle)

If bytChoice = vbYes Then
  Confirm = True
Else
  Confirm = False
End If

End Function

The code to use this function is much easier to write than the call to MsgBox because you can embed it into an If Confirm("Are you sure", "Delete record") Then...

An additional bonus in our work is that we have no longer have to remember the different calling conventions and the different names for the constants in the FoxPro and Access messageboxes - we have written a "Confirm" function in both languages.

Back to Access Developers' page

Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map