Solved

How to update/refresh a textbox?

Posted on 2003-11-17
9
857 Views
Last Modified: 2010-05-18
I have a small problem.
On the first form I have coded some arithmetical operations. When the operations are done you can open the results form with a cmdButton. You can go back and change some inputvalues on the first form and make new arithmetical operations, but when you open the results form again, the textboxes haven't been updated.

In the main form the results are stored in different public variables. In the results form the textboxes are set like this:

txtSupportingForce.txt = varSF

It works like it should the first time but when I make new calculations the textboxes have the same values as the first time.



Is there some code to write in the form_load function to get the textboxes updated?
0
Comment
Question by:HLEA
[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
9 Comments
 

Author Comment

by:HLEA
ID: 9766780
Oops, it's really spelled:            txtSupportingForce.Text = varSF
0
 
LVL 2

Expert Comment

by:UriS
ID: 9766841
I suppose you have 2 options:
1. If the 2nd form is valid while you calculate...
    update the 2nd form's textbox when the calculation ends with something like...Form2.Text1.Text = varResult.

2. Declare a public variable/private variable+public function in the 1st form and when you open the 2nd form_load call that function/variable to retreive the result.

Text1.Text = Form1.varResult     or
Text1.Text  = Form1.GetResult()

Public varResult as Variant    
--------------------------------  or
Private varResult as Variant
Public Function GetResult() as Variant
    GetResult = varResult
End Function
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9766888
shouldn't you use:
txtSupportingForce.refresh
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Expert Comment

by:danmian
ID: 9767109
hi HLEA, it is not nessesary to update any textbox, but try this

in the command button to load the result form use this at the beginning:

Private Sub Command1_Click()
' result form is the form called when the cmdButton is pressed
Unload ResultForm
Load ResultForm
ResultForm.txtSupportingForce.Text = varSF 'make sure VERY sure varSF has the right value
ResultForm.Show
...
End Sub


it's a forced way to reset all in the form

bye
:-)
0
 
LVL 7

Expert Comment

by:Enlade
ID: 9767131

I think what you have done is to put the update to your results form in the form load event.  However, you probably did not unload the form after the user closed it.  You probably just hide the form.  Then when you call show form for the second time since the form is already loaded it will not exicute the form load event.  Now, I'm not exactly sure what would be the best solution for what you are doing, but just to get it working for you make sure that you do a Me.Unload on the exit of the results form.  Then when you do the "frmResults.Show Me, Modal" or whatever it will cause the load event to be exicuted and thus update your text boxes properly.

0
 
LVL 7

Expert Comment

by:Enlade
ID: 9767150

Note that there are other ways to manage secondary forms.  For instance, you could create a public FormSetup function (call it whatever you want) and then call that function deliberatly from the main form.  For instance, lets say your results form is called frmResults then you would do something like this on the click event of your results button on your main form.

Load frmResults
frmResults.FormSetup
frmResults.Show Me, vbModal

Even though you call the load function above that does not mean that the load event of frmResults is called.  The load event only occurs if the form is actually loaded.  If instead the form is already loaded it will not initiate the load event.  Still, if you move you load event code over to a seperate public function (say FormSetup) then you will be assured that the code is exicuted because you call the FormSetup function deliberately prior to the Show function.

Like I said above you can avoid all this and just make sure that you unload the form properly before you try to show it again, but this is just another way to deal with a loaded form.  Hope that helps.
0
 
LVL 7

Accepted Solution

by:
Enlade earned 80 total points
ID: 9767164

Opps, that shouldn't be Me.Unload but rather:

Unload Me

Sorry about that.
0
 

Expert Comment

by:ace5342
ID: 9768338
or do it my way i anint good but i will say this is prob a long way lol

use a timer

i use loads of them lol

set the timer to what eva you want and you well away

Private Sub Timer1_Timer()
txtSupportingForce.Text = varSF
Timer1.Enabled = False
End Sub
0
 

Author Comment

by:HLEA
ID: 9770366
Thanks to you all!
Enlade, I'm giving you the points because Unload Me did it. The shortest and easiest way is best way for a beginner like me.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 1 hour left to enroll

636 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