Solved

To Refresh Form... vb6

Posted on 2004-09-15
3
1,680 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

717 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