Solved

How to update/refresh a textbox?

Posted on 2003-11-17
9
839 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

948 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

20 Experts available now in Live!

Get 1:1 Help Now