PDA

View Full Version : Validate Textbox before sending form



macca34
02-07-2014, 04:56 AM
Hi, hope someone can help.

I have three text boxes that I require users to complete before sending. I have trid to add a Exit Sub after the validation. This does work to an extent which it stops the form from sending (email attachment). However even after you have completed the three text boxes the form still doesn't send. Grateful for any help

macca34
02-07-2014, 09:23 AM
Can't seem to add the code (getting an error)


If ActiveDocument.CostCentre.Text = "" Then
If MsgBox("Please add Cost Centre", vbCritical + vbDefaultButton1, "STOP") = vbCancel Then
ActiveDocument.CostCentre.Text.Result = sFld
If ActiveDocument.ProgCode.Text = "" Then
If MsgBox("Please add Programme Code", vbCritical + vbDefaultButton1, "STOP") = vbCancel Then
ActiveDocument.ProgCode.Text.Result = sFld
End If
End If

If ActiveDocument.EntityCode.Text = "" Then
If MsgBox("Please add Entity Code", vbCritical + vbDefaultButton1, "STOP") = vbCancel Then
ActiveDocument.EntityCode.Text.Result = sFld
End If
End If
End Sub

westconn1
02-08-2014, 05:05 PM
there are a few issues here, 2 missing end if for first textbox, end sub should i would believe be exit sub, and should be in each if criteria, as it is it is processed every time regardless if the text boxes are not empty

as you message box only have one button, vbcancel can never be true
if it was you would then apply the same value (sFld) to all textboxes
you could use input boxes, for the user to complete each field, instead of the messageboxes

you should post more complete code as i am guessing at what i can not see