Results 1 to 3 of 3
  1. #1
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108

    Test if other form is loaded and requery subform

    I have a simple form I use to add items to an exclusion table.
    On add, it requeries the list box showing the table. I also want to requery a subform of ANOTHER form, if it is open, or do nothing if not open.

    The code works, except for the last subform refresh, I get an error "no field maned "form name" in the current record thought the name is correct.
    I tried to either refresh the form or the subform and get the same error.
    The "If form is open" test works as well, the requery does not.




    This is the code with the error
    Code:
    If CurrentProject.AllForms("frm_RequisitionSelector").IsLoaded Then 'test if form is already open
    DoCmd.Requery "frm_sub_Requisition_Items_Selection"
    End If
    This is the full code

    Code:
    Private Sub CmdExcludeItem_Click()
    DoCmd.SetWarnings False
    
    'Test if the text field is not empty
    If Len(Me.txtExcludeItem & vbNullString) = 0 Then
    MsgBox "Please enter an item ID"
    Else
    
    
    'test if value already in exclusion table
    If DCount("[Item_ID]", "tbl_Requisition_Exclusions", "[Item_ID] = txtExcludeItem") > 0 Then
    
    
    MsgBox "Item already excluded"
    
    
    'Emtpy text box value
    Me.txtExcludeItem.Value = Null
    
    
    Else
    
    
    DoCmd.RunSQL "INSERT INTO tbl_Requisition_Exclusions (Item_ID) VALUES ('" & txtExcludeItem & "')"
    
    
    MsgBox "Item added to exclustion list" & vbCrLf & "" & vbCrLf & "This item won't be selected again " & vbCrLf & "" & vbCrLf & "Data selection will now be refreshed"
    
    
    Me.txtExcludeItem.Value = Null
    End If
    
    
    'Refresh subform data
    DoCmd.OpenQuery "qry_DELETE_tbl_Requisitions_Select"
    DoCmd.OpenQuery "qry_AppendTo_tbl_Requisitions_Select"
    Me.Lst_ExcludedItems.Requery
    
    
    If CurrentProject.AllForms("frm_RequisitionSelector").IsLoaded Then 'test if form is already open
    DoCmd.Requery "frm_sub_Requisition_Items_Selection"
    End If
    
    End If
    DoCmd.SetWarnings True
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    DoCmd.Requery is not correct usage.

    Have to reference the parent form as well and the name of subform container control. I always name subform container different from the object it holds, like: ctrItems.

    Code:
    Forms!frm_RequisitionSelector.ctrItems.Requery
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108
    Yes, this works now, thank you so much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Requery Subform in Form.
    By Perfac in forum Queries
    Replies: 9
    Last Post: 02-12-2018, 08:39 AM
  2. Requery subform from main form
    By nswhit in forum Forms
    Replies: 7
    Last Post: 05-13-2013, 02:22 PM
  3. Requery Main Form, Keep Focus on Subform
    By burrina in forum Forms
    Replies: 8
    Last Post: 11-21-2012, 03:50 AM
  4. Replies: 3
    Last Post: 04-17-2012, 10:28 AM
  5. Subform empty when main form loaded
    By martyjward in forum Forms
    Replies: 1
    Last Post: 08-15-2011, 04:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums