ضعي هذا الكود في وحدة نمطية جديدة
Public Function IsOpen(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view.
Const conDesignView = 0
Const conObjStateClosed = 0
IsOpen = False
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> _
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsOpen = True
End If
End If
End Function
ومن ثم عدلي الكود الذن عندك الى
DoCmd.GoToRecord , , acNewRec
If IsOpen("frmCustomers") Then
CustomerID = Forms![frmCustomers]![CustomerID]
End If