Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Error trapping an Input Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Compass Rose - 30 Sep 2006 06:55 GMT
I have to error trap the following line of code:

ActiveDocument.Variables("varmeetingnumber").Value = InputBox("Meeting
Number")

If the user doesn't enter any number, I want to display a Message Box and
prompt the user again for a number.

Being new to VBA, I don't know the code to do this. Your help is appreciated.

TIA, David
Helmut Weber - 30 Sep 2006 08:56 GMT
Hi Compass Rose,

in what format should a meeting number be?
Largest number?
Smallest number?

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Compass Rose - 02 Oct 2006 00:39 GMT
Perhaps I didn't explain myself fully. I have to prepare and distribute the
minutes of a weekly meeting that I chair. The meetings are numbered
sequentially, and the number appears in various places in the document, hence
the prompt, and I place a DOCVARIABLE in those places in the document where
they are needed.

If, by mistake, a wrong meeting number is entered or a null value is
entered, I want to be able to error trap those conditions. I don't know the
syntax to accomplish this.

I hope this is clearer now.

> Hi Compass Rose,
>
> in what format should a meeting number be?
> Largest number?
> Smallest number?
Jean-Guy Marcil - 02 Oct 2006 06:11 GMT
Compass Rose was telling us:
Compass Rose nous racontait que :

> Perhaps I didn't explain myself fully. I have to prepare and
> distribute the minutes of a weekly meeting that I chair. The meetings
[quoted text clipped - 7 lines]
>
> I hope this is clearer now.

You were perfectly clear.

What Helmut wanted to know were the parameters to use for the logic that
will be needed to decide if a given number is acceptable.
For example, the following are numbers, but probably unacceptable as meeting
numbers: "123.45", "-56" or "567,678".

In any case, here is a sample that accepts any number..

Dim lngMeet As Variant
Dim boolOK As Boolean

Do
   lngMeet = InputBox("Meeting Number")
   'lngMeet  = "" when user clicks on "Cancel"
   If lngMeet = "" Then Exit Sub
   If Not IsNumeric(lngMeet) Then
       MsgBox "You must type a valid standard number."
       boolOK = False
   Else
       boolOK = True
       ActiveDocument.Variables("varmeetingnumber").Value = CStr(lngMeet)
   End If
Loop While Not boolOK

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Compass Rose - 04 Oct 2006 06:44 GMT
Merci beacoup, Jean-Guy. This does exactly what I want.

However, I found one small glitch. I changed

If Not IsNumeric(lngMeet) Then

to

If Val(lngMeet) <> Int(Val(lngMeet)) Then

Thanks again,
David

> Compass Rose was telling us:
> Compass Rose nous racontait que :
[quoted text clipped - 35 lines]
>     End If
> Loop While Not boolOK
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.