Solved

To Refresh Form... vb6

Posted on 2004-09-15
3
1,599 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 33

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

744 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

14 Experts available now in Live!

Get 1:1 Help Now