The following is probably not doing what you think it is doing.
DoCmd.RunCommand acCmdSave
I had my doubts about that one but I had tried so many options and it wasn't creating an error so I just left it in.
Your suggestions make perfect sense. Especially forcing the save of frmOrders on the Unload event of ShipTo. I didn't realize how that event differs from On Close but I do now. However, I'm still not getting cboPickPrevShipTo on the Orders Form to requery/refresh/or the form record to save. Again, the values entered are going into the table and once the record on Orders is manually saved the newly added record from ShipTo form is there in cboPickPrevShipTo .
To give you some more info:
The cboPickPrevShipTo is not in a subform on frmOrders.
Here is the code on the OnClick Event of of the Command Button That opens frmShipTo:
Code:
Private Sub cboAddNewShipTo_Click()
DoCmd.OpenForm "frmShipTo", _
DataMode:=acFormAdd, _
OpenArgs:=Me.Combo27
End Sub
This is selecting the customerID to use on the frmShipTo (which works fine)
This is the IsFormLoaded Module:
Code:
Function IsFormLoaded(ByVal strFormName As String) As Integer
'======================================
'Returns True if the specified form is open in Form view or Datasheet view.
'Test to make sur that a form is open (IsLoaded) before a procedure is run.
'======================================
On Error GoTo ErrHandler
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
Exit Function
ErrHandler:
MsgBox "Error: " & Err.Number & " - " & Err.Description, vbInformation, "Opps Error"
Exit Function
End Function
Finally, here is the code you suggested in the Unload event of frmShipTo (I did try other variations of this which didn't work, but it's back to your suggested code):
Code:
Private Sub Form_Unload(Cancel As Integer)
If Me.Dirty Then Me.Dirty = False
If IsFormLoaded("frmOrders") = True Then
If Forms!frmOrders.Dirty = True Then
'Commit the values in the bound controls to the table.
Forms!frmOrders.Dirty = False
'Requery the combo
Forms![frmOrders].[cboPickPrevShipTo].Requery
End If 'frmOrders.Dirty
End If 'IsFormLoaded
End Sub
I appreciate your further thoughts on this. I know it's an issue that has cropped up for a lot of people by reading other threads and there seems to be a myriad of answers and trials that have been made to solve this issue for many.
Thanks