How to update values in message boxes from within VBA?

M

Michael T

I have a macro (in VB) as shown down below invoked by F11 - I created it
initially
with record macro. It allows me to type in a name for an invoice and
increment
the invoice number.

When I first press F11 it invokes two consecutive
message boxes to accept input to update two fields on the invoice.

The first message box comes up with the current value of the field from the
invoice template (Client Name).
I change the name in the this first message box and press OK on the message
box.

The second message box comes up with the current value of the field from the
invoice template (01) which is fine for the first invoice so I press OK on
the message box and the macro then prints the invoice.

When I next press F11 the first message box pops up with the previous value
that I have typed in last (a name), I alter this, press OK and then the next
message
box pops up with the invoice number value from the invoice template (i.e.
01). What I
would like to do is to increment the value of the invoice number field
displayed BEFORE the second message box pops up - specifically to add 1 to
the value of a counter so that I don't normally have to change it.

The trouble is that I do not seem to be able to access the value in the
Message Box from within VB since the Message Box processing is automatic and
does not actually appear in the VB code.

Does anyone have any ideas please?

Thanks, Michael.

------------------------------------------------------------------------------

Sub ClientReceipt()
'
' ClientReceipt Macro
' Macro recorded 13/04/2008 by M Tidbury
' Invoked by F11
' Fields include:
' "REF ReceiptHeader" which is the -NN at the end of the receipt number

Selection.WholeStory
Selection.Fields.Update ' Invoke dialogue boxes to
update fields
Selection.EscapeKey
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
'ActiveDocument.PrintOut
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0,
_
PrintZoomPaperHeight:=0
End Sub
 
M

Michael T

Hi Macropod,

Thanks for your reply. It was the correct procedure. When I used Debug,
pressing F11 invokes the Selection.Wholestory then stepping through with F8
the Selection.Fields.Update goes yellow and the first Message box pops up,
after I input the name and press ok than the second - I don't know where the
code for that actually is! Is it some form of built-in function but then
where does it store the strings that I typed in when recording the macro:
First message box "Client name?" and second message box "Input receipt
number NN"?

I shall try your suggestion in the meantime.

Many thanks Michael.

macropod said:
Hi Michael,

Did you post the correct sub? There's no MsgBox or incrementing code in
what you posted. FWIW, to solicit input you need an InputBox rather than a
MsgBox. For example:

Sub Test()
Dim Val As String
Val = InputBox("Please input a number.")
If IsNumeric(Val) Then MsgBox Val + 1
End Sub

For some auto-incrementing code, see my posts in:
http://www.techsupportforum.com/mic...uentially-numbered-documents-word-2007-a.html


--
Cheers
macropod
[Microsoft MVP - Word]


Michael T said:
I have a macro (in VB) as shown down below invoked by F11 - I created it
initially
with record macro. It allows me to type in a name for an invoice and
increment
the invoice number.

When I first press F11 it invokes two consecutive
message boxes to accept input to update two fields on the invoice.

The first message box comes up with the current value of the field from
the
invoice template (Client Name).
I change the name in the this first message box and press OK on the
message
box.

The second message box comes up with the current value of the field from
the
invoice template (01) which is fine for the first invoice so I press OK
on
the message box and the macro then prints the invoice.

When I next press F11 the first message box pops up with the previous
value
that I have typed in last (a name), I alter this, press OK and then the
next
message
box pops up with the invoice number value from the invoice template (i.e.
01). What I
would like to do is to increment the value of the invoice number field
displayed BEFORE the second message box pops up - specifically to add 1
to
the value of a counter so that I don't normally have to change it.

The trouble is that I do not seem to be able to access the value in the
Message Box from within VB since the Message Box processing is automatic
and
does not actually appear in the VB code.

Does anyone have any ideas please?

Thanks, Michael.

------------------------------------------------------------------------------

Sub ClientReceipt()
'
' ClientReceipt Macro
' Macro recorded 13/04/2008 by M Tidbury
' Invoked by F11
' Fields include:
' "REF ReceiptHeader" which is the -NN at the end of the receipt number

Selection.WholeStory
Selection.Fields.Update ' Invoke dialogue boxes to
update fields
Selection.EscapeKey
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
'ActiveDocument.PrintOut
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0,
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
 
D

Doug Robbins - Word MVP

Sounds then like you must be using Ask or Fillin fields, NOT InputBoxes as
that term pertains to Visual Basic.

I would suggest that you should consider using a userform.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

and the following pages of fellow MVP Greg Maxey's website :

http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Michael T said:
Hi Macropod,

Thanks for your reply. It was the correct procedure. When I used Debug,
pressing F11 invokes the Selection.Wholestory then stepping through with
F8 the Selection.Fields.Update goes yellow and the first Message box pops
up, after I input the name and press ok than the second - I don't know
where the code for that actually is! Is it some form of built-in function
but then where does it store the strings that I typed in when recording
the macro: First message box "Client name?" and second message box "Input
receipt number NN"?

I shall try your suggestion in the meantime.

Many thanks Michael.

macropod said:
Hi Michael,

Did you post the correct sub? There's no MsgBox or incrementing code in
what you posted. FWIW, to solicit input you need an InputBox rather than
a MsgBox. For example:

Sub Test()
Dim Val As String
Val = InputBox("Please input a number.")
If IsNumeric(Val) Then MsgBox Val + 1
End Sub

For some auto-incrementing code, see my posts in:
http://www.techsupportforum.com/mic...uentially-numbered-documents-word-2007-a.html


--
Cheers
macropod
[Microsoft MVP - Word]


Michael T said:
I have a macro (in VB) as shown down below invoked by F11 - I created it
initially
with record macro. It allows me to type in a name for an invoice and
increment
the invoice number.

When I first press F11 it invokes two consecutive
message boxes to accept input to update two fields on the invoice.

The first message box comes up with the current value of the field from
the
invoice template (Client Name).
I change the name in the this first message box and press OK on the
message
box.

The second message box comes up with the current value of the field from
the
invoice template (01) which is fine for the first invoice so I press OK
on
the message box and the macro then prints the invoice.

When I next press F11 the first message box pops up with the previous
value
that I have typed in last (a name), I alter this, press OK and then the
next
message
box pops up with the invoice number value from the invoice template
(i.e.
01). What I
would like to do is to increment the value of the invoice number field
displayed BEFORE the second message box pops up - specifically to add 1
to
the value of a counter so that I don't normally have to change it.

The trouble is that I do not seem to be able to access the value in the
Message Box from within VB since the Message Box processing is automatic
and
does not actually appear in the VB code.

Does anyone have any ideas please?

Thanks, Michael.

------------------------------------------------------------------------------

Sub ClientReceipt()
'
' ClientReceipt Macro
' Macro recorded 13/04/2008 by M Tidbury
' Invoked by F11
' Fields include:
' "REF ReceiptHeader" which is the -NN at the end of the receipt number

Selection.WholeStory
Selection.Fields.Update ' Invoke dialogue boxes
to update fields
Selection.EscapeKey
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
'ActiveDocument.PrintOut
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:=
_
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0,
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
 
M

Michael T

Thank you, Doug.

I shall try these out.

All the best,

Michael.

Doug Robbins - Word MVP said:
Sounds then like you must be using Ask or Fillin fields, NOT InputBoxes as
that term pertains to Visual Basic.

I would suggest that you should consider using a userform.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

and the following pages of fellow MVP Greg Maxey's website :

http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm

http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Michael T said:
Hi Macropod,

Thanks for your reply. It was the correct procedure. When I used Debug,
pressing F11 invokes the Selection.Wholestory then stepping through with
F8 the Selection.Fields.Update goes yellow and the first Message box pops
up, after I input the name and press ok than the second - I don't know
where the code for that actually is! Is it some form of built-in function
but then where does it store the strings that I typed in when recording
the macro: First message box "Client name?" and second message box "Input
receipt number NN"?

I shall try your suggestion in the meantime.

Many thanks Michael.

macropod said:
Hi Michael,

Did you post the correct sub? There's no MsgBox or incrementing code in
what you posted. FWIW, to solicit input you need an InputBox rather than
a MsgBox. For example:

Sub Test()
Dim Val As String
Val = InputBox("Please input a number.")
If IsNumeric(Val) Then MsgBox Val + 1
End Sub

For some auto-incrementing code, see my posts in:
http://www.techsupportforum.com/mic...uentially-numbered-documents-word-2007-a.html


--
Cheers
macropod
[Microsoft MVP - Word]


I have a macro (in VB) as shown down below invoked by F11 - I created it
initially
with record macro. It allows me to type in a name for an invoice and
increment
the invoice number.

When I first press F11 it invokes two consecutive
message boxes to accept input to update two fields on the invoice.

The first message box comes up with the current value of the field from
the
invoice template (Client Name).
I change the name in the this first message box and press OK on the
message
box.

The second message box comes up with the current value of the field
from the
invoice template (01) which is fine for the first invoice so I press OK
on
the message box and the macro then prints the invoice.

When I next press F11 the first message box pops up with the previous
value
that I have typed in last (a name), I alter this, press OK and then the
next
message
box pops up with the invoice number value from the invoice template
(i.e.
01). What I
would like to do is to increment the value of the invoice number field
displayed BEFORE the second message box pops up - specifically to add 1
to
the value of a counter so that I don't normally have to change it.

The trouble is that I do not seem to be able to access the value in the
Message Box from within VB since the Message Box processing is
automatic and
does not actually appear in the VB code.

Does anyone have any ideas please?

Thanks, Michael.

------------------------------------------------------------------------------

Sub ClientReceipt()
'
' ClientReceipt Macro
' Macro recorded 13/04/2008 by M Tidbury
' Invoked by F11
' Fields include:
' "REF ReceiptHeader" which is the -NN at the end of the receipt number

Selection.WholeStory
Selection.Fields.Update ' Invoke dialogue boxes
to update fields
Selection.EscapeKey
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
'ActiveDocument.PrintOut
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:=
_
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0,
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
 

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