Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message box using VBA 1

Status
Not open for further replies.

kabushnell

Technical User
Jun 4, 2003
81
US
I have a user form in a Word template that I would like to add a message box if some of the data is not filled in. The form has a series of text and combo boxes along with radio buttons. I would like to have a message box open if some of the text boxes do not have data in them. I am assuming you would use an If statement but I can't seem to make it work.

Any suggestions??
 
kabushnell

I'm no expert in VBA but I've used it in PowerPoint. Try a search in Google.com with the following expression:

use messagebox using vba in word

Hope it helps
Lee.....

Alone we can do so little, together we can do so much
(VisFox Version 6 User)
 
When you say "user form", are you referring to a form created in VBA, or a form containing fields in the normal Word screen?

If it's a user form in VBA, your "OK" button or similar can have some validation in the On Click event. To view the code for the button, double-click on the button in the VBA window. Your code might look something like the following:

Code:
Private Sub cmdOK_Click()
    If frmCustom.txtLocation = "" Then
        MsgBox "You must fill in all fields!", vbExclamation, _
            "Data Incomplete"
        frmCustom.txtLocation.SetFocus
    End If
End Sub

If you have created a form in the Word document window, you can create a macro that looks something like the following:

Code:
Private Sub CheckLocation()
    If Me.FormFields("txtLocation").Result = "" Then
        MsgBox "You must complete all fields", vbExclamation, _
            "Data Incomplete"
    End If
End Sub

You then select this macro as the "Exit" macro for your form field.
 
Thanks, it is a form in VBA with an OK button. I was trying MessageBoxShow but I see now that in VBA it is MsgBox.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top