Solved

Excel/VB EditBox: assigning variable name to inputs

Posted on 1997-08-19
7
392 Views
Last Modified: 2008-03-17
I have created a DialogBox with a number of different EditBoxes. In these EditBoxes, I wish to input data to which I would like to assign a variable name, later to be used in my code. What I have written so far looks as below (if I could get it to work, I'd be set,since this code would mean that I have successfully assigned EditBox inputs to a variable).

Sub DialogBox()
>     DialogSheets("Dialog1").EditBoxes(1).Text = 100
>     DialogSheets("Dialog1").EditBoxes(2).Text = 12
>     DialogSheets("Dialog1").Show
>     Set iterations = DialogSheets("Dialog1").EditBoxes(1)
>     Sheets("Assumptions Sheet").Activate
>     Range("A13").Value = iterations
> End Sub

My problem is that the DialogSheets object does not support the Value property -- how can I get around this?

With kind regards,

Olivier
0
Comment
Question by:ODefaux
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:ChrisLewis
Comment Utility
I believe what you want to do is use the  .TEXT property to return the value of a edit box.  

Similar to what you have written above, bu use the following:

Set iterations = DialogSheets("Dialog1").EditBoxes(1).text
Sheets("Assumptions Sheet").Activate
Range("A13").Value = iterations

Hope this helps.

CHris
0
 

Author Comment

by:ODefaux
Comment Utility
The text property yields run-time error '424' -- object required.
0
 

Author Comment

by:ODefaux
Comment Utility
The text property returns a run-time error 424 -- object required.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 3

Expert Comment

by:ChrisLewis
Comment Utility
First of all, what line is the error being generated on.  

Second, if you go into debug mode at the SET ITERATIONS line, can you print what DialogSheets("Dialog1").EditBoxes(1).Text is.

Third, what do you have iterations declared as.  And are you using Option Explicit.  

Fourth, try
Range("A13").Value = DialogSheets("Dialog1").EditBoxes(1).text
instead of using the set variable.

Most likely, there's something funky with how you are declaring Iterations.  Sorry I didn't pick this up, but the SET keyword should have tipped me.  Set is used for objects, and you should be just using a straight assignment.

I use this code all over the place in a system with 5 dialogs with 10 fields each.  I haven't ever had a problem with this, but I use the RANGE() = Dialog,Editbox.text without the intermediate variable.


DIM iterations as STRING
iterations = DialogSheets("Dialog1").EditBoxes(1).text
Sheets("Assumptions Sheet").Activate
Range("A13").Value = iterations

Hope this helps,

Chris
0
 

Author Comment

by:ODefaux
Comment Utility
Dear Chris,

In answer to your questions

The error is being generated on the "Set iterations" line -- run-time error 424 (object required).

I can 't print this line as I am currently not hooked up to a printer.

I am using Option Explicit and have iterations dimensioned as a Variant (only thing that doesn't seem to generate an error).

I tried setting Range("A13").Value = DialogSheets("Dialog1").EditBoxes(1).text just to see and it didn't work (run-time error 1004 -- Range method of Application class failed).  I actually need the iterations variable in my code to dimension a simulation I am doing, so even if it had worked, I still would have had to find a way to assign the Edit Box input to a variable name.  Perhaps one way would be to place the value in a range on the spreadsheet and then assign it a variable name?

Hope this clarifies somewhat.  I've been stuck on this for weeks.

Thanks again for your help. Sorry I have to keep rejecting your answer until I get closer to making this thing work.

Olivier

0
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 130 total points
Comment Utility
Olivier

By print, I mean to type this in the debug window:

? DialogSheets("Dialog1").EditBoxes(1).text

and press enter.  Put a break point on the line in code to bring up the debug window.  You should get what's in the edit control.

For the iterations, use a straight assignment, not the Set command. Set can only be used for objects, not for variables.

iterations = DialogSheets("Dialog1").EditBoxes(1).text

Your error 1004 has to do with your range, not with the dialog box, so look at how you are assigning your range.  Make sure that the sheet the range is on is active.

Hope this helps,

Chris


0
 

Author Comment

by:ODefaux
Comment Utility
The straight assignment did the trick (no set command)!  Thanks for the assistance and persistence.

Olivier
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now