J
jdbash
So I have been working on this database for quite some time. It uses a
custom toolbar as the menu. Each button passes a value through the
following function...
Public Function openForm(strFormOpen As String)
DoCmd.Close
DoCmd.openForm (strFormOpen)
End Function
So if I click on a button in my menu, under it properties I would
designate on action:
=openForm("formname I am opening")
Here is my dilemma: I have a form where users enter records. If they
exit the form by clicking on one of the buttons in the menu I do not
want the record to save unless certain criteria is met. In most cases
this can be accomplished in a me.undo in the BeforeUpdate, but this
wont work in my special case.....
Lets assume a user clicks a menu button which will eventually call the
openForm function I have listed above. Here is the code within my form
class module that I have written:
The name of the form is "frm_EPCN"
Private Sub Form_BeforeUpdate(Cancel As Integer)
'''''If the EPCN does not have an ID then the openForm function should
occur
If txtEPCNID = "" Or IsNull(txtEPCNID) Then
Exit Sub
''''If the EPCN does have an ID the following procedure should run..
Else
Call EPCNControl
End If
End Sub
'''Now, if the user has not completed the originator field they will be
prompted to either exit the form, thereby discarding their changes or
return to the form to continue editing.
Public Sub EPCNControl()
If cboOriginator = "" Or IsNull(cboOriginator) Then
If MsgBox("You have created a partial record. If you exit the form now
this record will not be saved. Are you sure you wish to exit?", vbYesNo
+ vbDefaultButton2) <> vbYes Then
''''Here is where the original function that was called by clicking the
toolbar button shouldbe canceled. However, instead of returing the user
to the cboOriginator field, the form exits.
DoCmd.SetWarnings False
DoCmd.CancelEvent
cboOriginator.SetFocus
Else
"""If the user selected yes, than the record changes are discarded and
the openForm function commences
Me.Undo
End If
End If
End Sub
NOW,
I have tried the same concept on the Unload event, but it is too late
to execute the Me.Undo
event.
My thought was to change the original public function to something
similar to this
Public Function openForm(strFormOpen As String)
Dim strFormName As String
strFormName = Me.form
If strFormName = frm_EPCN
then
''call the same logic as is in the class module for frm_EPCN
Else
DoCmd.Close
DoCmd.openForm (strFormOpen)
End Function
This way whenever other navigation buttons are clicked on the toolbar
it will just skip to closing the current form and opening whatever form
is clicked on. If it is indeed the frm_EPCN the proper motions will
take place and the opening/closing of the form will be canceled if
certain criteria is not met.
MY problem is as easy as the Me.form. It does not work in the module,
since its not a class module. In this situation how can I make sure the
form the user is focused on is passed through the function?
Any help and I will send you 1000 cake doughnuts!!
Thanks,
Justin
custom toolbar as the menu. Each button passes a value through the
following function...
Public Function openForm(strFormOpen As String)
DoCmd.Close
DoCmd.openForm (strFormOpen)
End Function
So if I click on a button in my menu, under it properties I would
designate on action:
=openForm("formname I am opening")
Here is my dilemma: I have a form where users enter records. If they
exit the form by clicking on one of the buttons in the menu I do not
want the record to save unless certain criteria is met. In most cases
this can be accomplished in a me.undo in the BeforeUpdate, but this
wont work in my special case.....
Lets assume a user clicks a menu button which will eventually call the
openForm function I have listed above. Here is the code within my form
class module that I have written:
The name of the form is "frm_EPCN"
Private Sub Form_BeforeUpdate(Cancel As Integer)
'''''If the EPCN does not have an ID then the openForm function should
occur
If txtEPCNID = "" Or IsNull(txtEPCNID) Then
Exit Sub
''''If the EPCN does have an ID the following procedure should run..
Else
Call EPCNControl
End If
End Sub
'''Now, if the user has not completed the originator field they will be
prompted to either exit the form, thereby discarding their changes or
return to the form to continue editing.
Public Sub EPCNControl()
If cboOriginator = "" Or IsNull(cboOriginator) Then
If MsgBox("You have created a partial record. If you exit the form now
this record will not be saved. Are you sure you wish to exit?", vbYesNo
+ vbDefaultButton2) <> vbYes Then
''''Here is where the original function that was called by clicking the
toolbar button shouldbe canceled. However, instead of returing the user
to the cboOriginator field, the form exits.
DoCmd.SetWarnings False
DoCmd.CancelEvent
cboOriginator.SetFocus
Else
"""If the user selected yes, than the record changes are discarded and
the openForm function commences
Me.Undo
End If
End If
End Sub
NOW,
I have tried the same concept on the Unload event, but it is too late
to execute the Me.Undo
event.
My thought was to change the original public function to something
similar to this
Public Function openForm(strFormOpen As String)
Dim strFormName As String
strFormName = Me.form
If strFormName = frm_EPCN
then
''call the same logic as is in the class module for frm_EPCN
Else
DoCmd.Close
DoCmd.openForm (strFormOpen)
End Function
This way whenever other navigation buttons are clicked on the toolbar
it will just skip to closing the current form and opening whatever form
is clicked on. If it is indeed the frm_EPCN the proper motions will
take place and the opening/closing of the form will be canceled if
certain criteria is not met.
MY problem is as easy as the Me.form. It does not work in the module,
since its not a class module. In this situation how can I make sure the
form the user is focused on is passed through the function?
Any help and I will send you 1000 cake doughnuts!!
Thanks,
Justin