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