Seeing value in textbox

W

willing2learn

I am running a VB script and want to have an amount entered in an input box
for display in a textbox. The value is only being displayed after all the
code is executed and not after the Ok button of the input box is selected as
I would wish to happen. These controls are on a worksheet. What can I do?


David
 
M

matt

I am running a VB script and want to have an amount entered in an input box
for display in a textbox. The value is only being displayed after all the
code is executed and not after the Ok button of the input box is selected as
I would wish to happen. These controls are on a worksheet. What can I do?

David

David,

If you are looking for the InputBox value to appear in the text box
right after the InputBox "OK" button is pressed, then place the line
of code in your program that takes the InputBox variable (and
subsequently writes that variable to the text box) right after the
InputBox line of code.
From your problem description, that's the best answer I can give you.
If you need something more specific, post some code or write a problem
description that is more detailed.

Matt
 
W

willing2learn via OfficeKB.com

matt said:
David,

If you are looking for the InputBox value to appear in the text box
right after the InputBox "OK" button is pressed, then place the line
of code in your program that takes the InputBox variable (and
subsequently writes that variable to the text box) right after the
InputBox line of code.

If you need something more specific, post some code or write a problem
description that is more detailed.

Matt

Hi Matt

That's just what I am doing but I am really at a loss as to why my textbox is
not displaying the vale.

Here is some of the code.

Dim Value1, Value2
Value1 = Application.InputBox(prompt:="Enter Deductions Amount", Type:=1)
If Value1 = False Then
End
Else
Worksheets("Cover").TextBox3.Value = Value1
End If
Value2 = Application.InputBox(prompt:="Enter Net Cheques Amount", Type:=1)
If Value2 = False Then
End
Else
Worksheets("Cover").TextBox4.Value = Value2
End If
 
M

matt

Hi Matt

That's just what I am doing but I am really at a loss as to why my textbox is
not displaying the vale.

Here is some of the code.

Dim Value1, Value2
Value1 = Application.InputBox(prompt:="Enter Deductions Amount", Type:=1)
If Value1 = False Then
End
Else
Worksheets("Cover").TextBox3.Value = Value1
End If
Value2 = Application.InputBox(prompt:="Enter Net Cheques Amount", Type:=1)
If Value2 = False Then
End
Else
Worksheets("Cover").TextBox4.Value = Value2
End If

Try this:

Worksheets("Cover").Shapes("Text Box 1").Select
Selection.Characters.Text = Value1

It should do the job.

Matt
 
W

willing2learn via OfficeKB.com

matt said:
[quoted text clipped - 42 lines]
- Show quoted text -

Try this:

Worksheets("Cover").Shapes("Text Box 1").Select
Selection.Characters.Text = Value1

It should do the job.

Matt
I got run time error '438'
on code Selection.Characters.Text = Value1
 
M

matt

matt said:
I am running a VB script and want to have an amount entered in an input box
for display in a textbox. The value is only being displayed after all the
[quoted text clipped - 42 lines]
- Show quoted text -
Try this:
Worksheets("Cover").Shapes("Text Box 1").Select
Selection.Characters.Text = Value1
It should do the job.

I got run time error '438'
on code Selection.Characters.Text = Value1

I'm not sure why you are getting the run-time error. Here's another
swing at it:

Worksheets("Cover").Shapes("Text Box 1").TextFrame.Characters.Text =
Value1

Maybe this will help, maybe it won't. When I run the code with my
previous post as well as the above line, they both work equally as
well. I'm a bit baffled.

Matt
 
W

willing2learn via OfficeKB.com

matt said:
[quoted text clipped - 20 lines]
- Show quoted text -

I'm not sure why you are getting the run-time error. Here's another
swing at it:

Worksheets("Cover").Shapes("Text Box 1").TextFrame.Characters.Text =
Value1

Maybe this will help, maybe it won't. When I run the code with my
previous post as well as the above line, they both work equally as
well. I'm a bit baffled.

Matt
Hi Matt
Is there any particular event from which you are running your code? Mine is
in a procedure which is part of the entire script. How are you testing this?
If I have a few lines of code then it would seen fine, but because my
routines run for almost a minute my textbox values only appear after all the
code has finish executing.
 
M

matt

matt said:
On Mar 23, 3:43 am, "willing2learn via OfficeKB.com" <u32721@uwe>
wrote:
[quoted text clipped - 20 lines]
- Show quoted text -
I'm not sure why you are getting the run-time error. Here's another
swing at it:
Worksheets("Cover").Shapes("Text Box 1").TextFrame.Characters.Text =
Value1
Maybe this will help, maybe it won't. When I run the code with my
previous post as well as the above line, they both work equally as
well. I'm a bit baffled.

Hi Matt
Is there any particular event from which you are running your code? Mine is
in a procedure which is part of the entire script. How are you testing this?
If I have a few lines of code then it would seen fine, but because my
routines run for almost a minute my textbox values only appear after all the
code has finish executing.


I'm testing my code by simply drawing 2 text boxes into Excel and then
running the code through in a module. I copied your code into my
module and tested it with the 2 text boxes I placed in the worksheet.
The only other thing that I can think for you to do is to write a
For...Each loop for the shape names and verify that you are indeed
referring to "Text Box 1" and "Text Box 2".

Matt

Sub shapesNames()
Dim a As Variant

For Each a In ActiveSheet.Shapes
Debug.Print a.Name
Next

End Sub
 
N

Nick Hebb

To add onto what Matt wrote, I would recommend breaking your code into
smaller sub procedures, with called from the event procedure that
you're working with. It makes it much easier to test and logically
organize your program. Plus, you can write small test functions for
each sub to run independently, saving you a lot of debugging time in
the long run.

- Nick Hebb
 

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