[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

To Refresh Form... vb6

Posted on 2004-09-15
3
Medium Priority
?
1,790 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 1200 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 400 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

872 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