Solved

How to update/refresh a textbox?

Posted on 2003-11-17
9
838 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now