Link to home
Start Free TrialLog in
Avatar of vremo
vremo

asked on

How to refresh a Tree View from another Form

I have a feature on my form where it allows you to add additional items from a pop-up form.  When the pop-up form is closed the items are added to the appropriate table and everything executes the way it should except for one.  

I'd like to have the main form refreshed when the pop-up form is closed.  If I close the form and then came back into it, the items are there.  I tried several solutions like the Forms.Refresh option but nothing works.  The items are displayed in a Tree View format which I'm thinking might be the issue at hand.  

Any thoughts?  Thanks
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

I assume you have a function in the main form to Load the treeview and/or refresh it?  If so, you need to Call that function from the Popup upon closing ....

mx
Avatar of vremo
vremo

ASKER

I tried Private, Public, and Function but non refresh the tree.  Below is the code from the form close sub.  Errors occur on the first two lines, they are nice to haves but not critical.  The last line is the one I need.  

The following is the first line in the public sub in the main form.
Public Sub fill_Tree(refreshTREE As Boolean, acode As Long)


Public Sub Form_Close()

Forms!frmMain!frmSub.cmdFinish.SetFocus
Forms!frmMain!frmSub.cmdFinish.StatusBarText = "SAVED!"
Forms!frmMain.fill_Tree True, Forms!frmMain!Code

End Sub

Open in new window

In the Main form ... be sure fill_Tree is a Public Function ... then try this:

Form_frmMain.fill_Tree

As for the other two lines:

Forms!frmMain!frmSub.cmdFinish.FORM.SetFocus
Forms!frmMain!frmSub.cmdFinish.FORM.StatusBarText = "SAVED!"

mx
Avatar of vremo

ASKER

I changed the main form so fill_Tree is a Public Function.  Now it looks like this:
Public Function fill_Tree(refreshTREE As Boolean, acode As Long)

The pop-up form now has this code:
Public Sub Form_Close()

Forms!frmMain!frmSub.Form!cmdFinish.SetFocus
Forms!frmMain!frmSub.Form!cmdFinish.StatusBarText = "SAVED!"
Forms!frmMain.fill_Tree True, Forms!frmMain.Form!Code.Value


End Sub


I don't recieve any error messages but it still doesn't execute any of the 3 lines.  Again I'm most concerned with the tree refreshing, could the issue be with passing the variables to the Public Function?
"but it still doesn't execute any of the 3 lines."
Are you saying the code in the Close event is not even firing?

And you need this syntax as I posted before - note dots instead of !

Forms!frmMain!frmSub.Form.cmdFinish.SetFocus
Forms!frmMain!frmSub.Form.cmdFinish.StatusBarText = "SAVED!"
' and you need to pass the arguments to the Tree function here
Form_frmMain.fill_Tree True, YouracodeVariableHere
                                            '  ^^^^^^^^^^^^^^^^^^^^^^^^^^   ??

mx
Avatar of vremo

ASKER

I made the changes but nothing is happening.  I installed an error handler in the sub and I get the following on the line where I pass the arguments to the tree function.

Error: 6 (Description: Overflow)

I thought this error was related to using integers?
Public Sub Form_Close()
On Error GoTo errorhandler

Forms!frmMain!frmSub.Form.cmdFinish.SetFocus
Forms!frmMain!frmSub.Form.cmdFinish.StatusBarText = "SAVED!"
Form_frmMain.fill_Tree True, Forms!frmMain.Form!Code.Value

errorhandler:
Call ErrorPop(Err.Number, Err.Description, Err.Source)

End Sub

Open in new window

Overflow means that there is an issue with the number value being passed ... due to the data type here:

Public Function fill_Tree(refreshTREE As Boolean, acode As Long)
                                                                                 ^^^^^^^^^^^^^^^

So ... something is wrong with:

Form_frmMain.fill_Tree True, Forms!frmMain.Form!Code.Value
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

maybe it's a Single or Double or ?????

mx

 
Avatar of vremo

ASKER

I checked the source of the texted field, it is coming from a table and the field is set as a long integer.  
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vremo

ASKER

OK, everything was correct but by setting a break point and stepping through the code and similar code, I realized I was missing a few lines.  unreal.  The tree now refreshes, the other two lines are not executing but they are not mission critical.  
"the other two lines are not executing but they are not mission critical.  "
Not executing ?  Meaning ?

mx