Custom Toolbars and Menu problem and questions

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
 
A

Albert D.Kallal

Often, (if not most of the time), you code you call will need to pick up
some information about the current screen etc. So, my code most of the time
starts out, and grabs the current screen name. I use:

Public Function AskInvoicePrint()

Dim tblgroupid As Long
Dim frmActive As Form

Set frmActive = Screen.ActiveForm

tblgroupid = frmActive.frmMainClientB.Form!ID

If frmActive.InvoiceNumber = 0 Then
frmActive.InvoiceNumber = nextinvoice
frmActive.Refresh
End If

DoCmd.OpenForm "guiInvoicePrint", , , "id = " & tblgroupid

End Function

The above is code that the invoice print button runs. note how I right away
pick up the active form. After that, I can easily ref the forms object as if
the code was running much like the code would if put behind a button on the
form. In the above example, I also check if a invoice number has been
generated before printing. And, the Refresh forces a disk write if in fact I
do change the invoice number. And, in addition the above clip also passes
the currently selected sub-form item that the invoice print form needs.

So, just pickup the name of the active form

Set frmActive = Screen.ActiveForm

Or,we could go

if screen.ActiveForm.name = "rm_EPCN" then
bla bla bla...
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top