Solved

Excel/VB EditBox: assigning variable name to inputs

Posted on 1997-08-19
7
406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:ChrisLewis
ID: 1431494
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
ID: 1431495
The text property yields run-time error '424' -- object required.
0
 

Author Comment

by:ODefaux
ID: 1431496
The text property returns a run-time error 424 -- object required.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:ChrisLewis
ID: 1431497
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
ID: 1431498
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
ID: 1431499
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
ID: 1431500
The straight assignment did the trick (no set command)!  Thanks for the assistance and persistence.

Olivier
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

729 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