Solved

To Refresh Form... vb6

Posted on 2004-09-15
3
1,634 Views
Last Modified: 2008-02-01
I have frmMain from which I access frmMaintenance (a popup form).  I click on cmdReset to:

cn.Execute "Delete * From tData"  'cn connection is global

frmMain.Form_Load           '<-- this gives error

The objective is to run Form_Load to remove all data from it (refresh it).  If I shouldn't be using Form_Load, how can I accomplish this task.

Thanks.                    
0
Comment
Question by:Mike Eghtebas
3 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 300 total points
ID: 12071407
Make your own (Public) Sub or Function which contains the code to reinitialize your variables, etc.

ex:

Public Sub MyInit()
    'Code here to initialize your variables
    'Call this in Form_Load, and from outside the form
End Sub

You can call a Public sub from another form, you cannot call a Private sub - that's where I think your error is.



Hope it helps!
0
 
LVL 5

Assisted Solution

by:KarcOrigin
KarcOrigin earned 100 total points
ID: 12071490
Try to do this:
Although there are many ways to do this here are two ways to do it.
One way -
frmMain.Form_Load event always read the data from the DB and put the values of it on the form controls. When you click on cmdReset button unload frmMain and load frmMaintenance popup form. Now do DB operations as deleting the data and reload frmMain form by frmMain.Show() by this your frmMain's Form_Load will again fetch the fresh data and will place it in the controls.

Other way -
If you do not want to unload your frmMain while loading frmMaintenance popup form then I will suggest you to use public functions to fetch the data and store the values in some intermediate variables. Now use these functions/intermediate variables to fetch and place the data in the controls on frmMain form. For this you can create a class with properties to hold your database values and can use it to set the values in the controls.

This is a possible flow-

1. cmdReset button clicked
2. Call the function to fetch the data and place it in the intermediate variable(s)
3. Call a function/sub to clear the frmMain data
4. Call another function/sub which will place the values from these intermediate variable to your frmMain controls.

The above steps are just the overview and not in details.
Regards,

I hope it will help you.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12072018
Erick37's post what I was missing.  Generally, I would have changed 'Private Sub Form_Load()' to 'Public Sub Form_Load()' but somehow I missed it.

I used 'Public Sub InitializeForm()' As recomended by Erick37 because it is much cleaner.

----------
In appreciation of KarcOrigin's post, I am increasing the points to spit it.  I hope Erick37 wouldn't mind.

Regards,

Mike
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 52
Visual Studio 2005 text editor 10 44
clicking a shape in a frame array vb6 3 46
MsgBox 4 68
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

856 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