Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 871
  • Last Modified:

How to update/refresh a textbox?

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
HLEA
Asked:
HLEA
1 Solution
 
HLEAAuthor Commented:
Oops, it's really spelled:            txtSupportingForce.Text = varSF
0
 
UriSCommented:
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
 
Richie_SimonettiCommented:
shouldn't you use:
txtSupportingForce.refresh
0
Independent Software Vendors: 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!

 
danmianCommented:
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
 
EnladeCommented:

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
 
EnladeCommented:

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
 
EnladeCommented:

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

Unload Me

Sorry about that.
0
 
ace5342Commented:
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
 
HLEAAuthor Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now