blocking the empty form submitting

A

Alex

I'm using Publisher form's controls on some page to give a visitor the
opportunity to send a message. It's working very good.
It's not a case for now at all. But, just to be proactive - I'm just
wondering whether it's possible to block sending e.g. completely empty
messages. If somebody wants just to press the Submit button 1,000 times
without entering the text, the 1,000 empty messages will be sent.

It's very easy to do it in VB for the userform - if it's emty then show some
message "you should enter a text", etc.

How would it be possible to do it with the Publisher form?

Thanks
 
E

Ed Bennett

Alex said:
It's very easy to do it in VB for the userform - if it's emty then
show some message "you should enter a text", etc.

This newsgroup is to do with VB and VBA.

The newsgroup for dealing with web-based forms and other Publisher web
issues is microsoft.public.publisher.webdesign.

I don't think custom validation options are available in Publisher, but I'm
not a web guru by any stretch of the imagination.
 
A

Alex

Thanks, Edd.

Sorry, that I wasn't so clear. But, I was meaning how to do it in VB. How I
could assign the VB code to the Publisher form controls - Text Boxes and Text
Area. To have somthing as
If IsNull(txtBox1) Then MsgBox("You should enter some text.")

Thanks
 
E

Ed Bennett

Alex said:
Sorry, that I wasn't so clear. But, I was meaning how to do it in VB.
How I could assign the VB code to the Publisher form controls - Text
Boxes and Text Area. To have somthing as
If IsNull(txtBox1) Then MsgBox("You should enter some text.")

Something along the lines of:

If ThisDocument.Pages(x).Shapes(y).TextFrame.TextRange.Length = 1 Then
Msgbox "You should enter some text"
Else
'do stuff
End If

N.B. A text frame will always contain at least one character - a paragraph
mark.
 
A

Alex

Thanks a lot, Ed. That's what I need.
Could you please advise how I could identify the Shape number in .Shape(y).

Thanks
 
E

Ed Bennett

Alex said:
Thanks a lot, Ed. That's what I need.
Could you please advise how I could identify the Shape number in
.Shape(y).

You would probably have to add a Tag to the shape and use a loop to search
for it.

Look up Tag in the Publisher VBA reference and try to work from there.
 
A

Alex

Thank you very much, Ed.

Ed Bennett said:
You would probably have to add a Tag to the shape and use a loop to search
for it.

Look up Tag in the Publisher VBA reference and try to work from there.
 
A

Alex

Ed, I forgot to ask how I could insert the code into the Submit button click
event.

For the userform it's clear - it's in the control properties. But, how about
the Form "Submit" button.

I'll research it again but for now it's not so clear to me how to find the
shape index - Y in the Shapes(y). To assign a tag I'll need to know the shape
index anyway.

Thanks
 
E

Ed Bennett

Alex said:
I'll research it again but for now it's not so clear to me how to
find the shape index - Y in the Shapes(y). To assign a tag I'll need
to know the shape index anyway.

You don't necessarily need to know the y to work with the shape. You can
assign it to a variable, or use a tag (or both). You can find out which
shape it is by using the Selection object, or by creating the shape through
VBA (and assigning it straight to a variable)
 
A

Alex

Ed, thank you very much for your help. Unfortunately I didn't have a chance
to work on it till now.
I found all my shapes numbers by using in immediate window
ActiveDocument.Pages(11).Shapes(y).Select entering different numbers instead
of y.

To use the code you advised before to block the empty form sending I need to
recognize the event when a user click the Submit button to interapt the
submition. There are no any properties for the Submit button such as click
event.
I would appreciate if you could advise how it's possible to do this.

Thanks
 
E

Ed Bennett

Alex said:
To use the code you advised before to block the empty form sending I
need to recognize the event when a user click the Submit button to
interapt the submition. There are no any properties for the Submit
button such as click event.
I would appreciate if you could advise how it's possible to do this.

You will need to create a CommandBarButton and use that as your submit
button.

I believe there is a tutorial on this at www.publishermvps.com. If not,
post back and I'll dig it out.

There are no events associated with individual shapes at all. You cannot
access the web events of web controls within a document.
 
A

Alex

Thanks again, Ed.

I couldn't find anything associated with this on the Publisher website.
But, i found your code that can relate to this:
"Here's some code I posted almost exactly two years ago to this group:

===
Public WithEvents cbbButton As Office.CommandBarButton


Sub Dummy()
MsgBox "Dummy"
End Sub


Private Sub cbbButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
Dummy
End Sub

Private Sub Document_BeforeClose(Cancel As Boolean)
cbbButton.Delete
End Sub

Private Sub Document_Open()
Dim cbBar As Office.CommandBar
On Error Resume Next
Set cbBar = Publisher.CommandBars("Macros")
If Err.Number = 0 Then
'everything is fine
Else
Set cbBar = Publisher.CommandBars.Add("Macros")
Err.Clear
End If
Set cbbButton = cbBar.Controls(msoControlButton)
If Err.Number = 0 Then
'everything is fine
Else
Set cbbButton = cbBar.Controls.Add(msoControlButton)
End If
Err.Clear
'you can insert some code to format the button here
End Sub
==="

But, now I have a well working form with the Submit button. Will it be
possible to give the CommandBarButton the same functionalities as the
existing Submit button?

Thanks
 
E

Ed Bennett

Alex said:
But, now I have a well working form with the Submit button. Will it be
possible to give the CommandBarButton the same functionalities as the
existing Submit button?

Tell me Alex, are you trying to create a web form with this submit button?
 
A

Alex

I've already created web site with the form with the text boxes/areas and
Submit button and published it. The submit form is working well. I'm just
thinking how to block the empty form submition.

Thanks
 
E

Ed Bennett

Alex said:
I've already created web site with the form with the text boxes/areas
and Submit button and published it. The submit form is working well.
I'm just thinking how to block the empty form submition.

I tried to explain before, but I think there was a bit of a
misunderstanding.

You CANNOT use VBA code on a web page. VBA code only works in the Publisher
environment.

For validation purposes you must use JavaScript or similar, which must be
manually added to the Publisher-generated HTML file. Alternatively, you
could have the form redirect to a server-side script that validates.

Either way, the best place to ask your question is the .webdesign newsgroup.

Apologies for any inconvenience I've caused.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top