Solved Treeview requery (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
I use a dialog form to edit and add new recipes. The following code is from the calling form.
Code:
Private Sub btnEdit_Click()
On Error GoTo btnEdit_Click_Error
    
    Me.Visible = False
    DoCmd.OpenForm "frmAddEdit", _
      windowmode:=acDialog, _
      OpenArgs:=Me.name
 
  'When you get back:
  If CurrentProject.AllForms("frmAddEdit").IsLoaded Then
    Me.Requery
'     TVW.reloadTree
'     faytRecipe.Requery
'     faytIngredient.Requery
     Me.Recordset.FindFirst "recipeid = " & Forms!frmAddEdit!recipeid
     DoCmd.Close acForm, "frmAddEdit"
It doesn't seem to matter where I requery the treeview, it doesn't pick up the new record and throws an error. Can you suggest a better way here?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
I assume that I am the only one to be able to answer this because you are using my TreeviewForm class module. I doubt others could answer that unless you provided a lot of background. In cases like that you may want to post this as a profile post or at least tag me in the thread.
The TVW.reload method does two things
removes all existing nodes
runs the load methods of the treeview form class

There are reason for removing and reloading instead of trying to simply add. At the table level a simple change of one parent ID could move a branch with 100s or more nodes.

If your loading using my method of a common query, after the record is added or modified the new record should appear in the query and it would be added since all records are readded.

If it is not two things could happen. The added record was not properly assigned a correct parent ID. If this is the case and it is not a root node then it could be disconnected. If its parent is never loaded because it is a bad ID then the child is never loaded.
The other issue could be that the form is still dirty and the data is not saved to the table.
After adding you new record, verify it exists in the Node query used to load the tree. Verify in the query it has a good parent ID.
 

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
I assumed when the dialog form closed the record was saved. Not? Oh Wait... It isn't closed, it's not visible until the calling form closes it. So... I should save the record before making invisible? Me.dirty, etc.
 
Last edited:

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
Also, while I have your attention, I have a FAYT combo that returns error 3078. It can't find the combo recordsource. I have 2 FAYT combos on this form and 2 on the calling form... Is there something I can do here? Like close them out or something?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
If you are doing a reload then you have to ensure the data is saved, as I explained.
I think I have a demo where I add or delete without a reload. This can be done if you know the new key and parent key for the add. For the delete you would just need the key (id) associated with the node. The edit is too complicated to try to do without simply reloading.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
3078 usually means "cannot find table or query". So I do not know enough of what you are doing to answer. The FAYT is probably loading when you load the form.
One thing with my FAYT's, they were not designed to work with parameter queries. If doing this you need to instead resolve and create the rowsource dynamically in code before loading and requerying. Also you have to use the Classes requery method.
 

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
Okay I've save the key but here is my problem: After requery the code jumps to current:
Code:
Private Sub Form_Current()
  Dim strKey
  On Error GoTo errlbl
  strKey = "RP" & Me.recipeid
     Me.TVW.TreeView.Nodes(strKey).Selected = True
     Me.TVW.TreeView.SelectedItem.EnsureVisible
     Me.TVW.TreeView.DropHighlight = Me.TVW.SelectedNode
  Exit Sub
the tree hasn't yet reloaded so an error happens.. Could you tell me how to coordinate these two events?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
Could you simply trap the error in this case?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
Or at least do a dlookup to see if the key exists in the query. If not exit the code.
 

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
Back to the FAYT.. I'm doing a faytRecipe.Requery and the recordsource is not a parameter query
Code:
SELECT [t_recipe].[RecipeID], [t_recipe].[recipename] FROM t_recipe ORDER BY [recipename];
very simple. I'm sorry about this, I'm just trying to do some last minute cleaning up so the users don't have to dodge these issues like I do.
The rowsource here is empty:
Code:
Public Property Get RowSource() As String
  RowSource = mRowSource
End Property
the FAYT works great until the requery
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
Are you using the requery method of the class? Requery the fayt object variable not the control.
 

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
Isn't that what I'm doing?
Code:
Public faytRecipe As New FindAsYouTypeCombo
faytRecipe.InitalizeFilterCombo Me.cboSearch, , AnywhereInString, True, False
first line in the header
second line in the load event
The control is called cboSearch
Code:
FAYTRecipe.Requery
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
That is correct.
Are you modifying the rowsource before the requery?
 

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
no. just saving a new record. It's the rowsource for a combo so how could I be modifying it?
 

ClaraBarton

Registered User.
Local time
Today, 11:23
Joined
Oct 14, 2019
Messages
467
The Treeview is now working! The FAYT problem seems to be intermittent... I'll figure something out. Thank you so much for your help, MajP.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:23
Joined
May 21, 2018
Messages
8,529
In the requery method of the class try changing it to
Code:
Public Sub Requery()
  'In order to requery must use the class requery not the controls requery
  'me.rowsource = me.rowsource
   Me.RowSource = Me.FilterComboBox.RowSource
End Sub

I think that is a typo, or I do not understand what I intended. Although either should work. The issue is if for some reason the property of the class
mRowSource is being set to "". This will repull the rowsource from the combobox and reset the properties.
 

Users who are viewing this thread

Top Bottom