Custom Menu Code In Form??

  • Thread starter Thread starter Judy
  • Start date Start date
J

Judy

I have a custom menu that is only used for one form. Is there a way to put
the functions for the menu items in the form's module rather than a standard
module?

Thanks!

Judy
 
Yes, you most certainly can do this. (and, in fact, as you ask..it is a good
idea!).

The solution is quite simple:

Simply make the function names public, and then place them in the form.

eg:


Public Function MyDelete()

' delete customer?

Dim strSql As String
Dim intShifts As Integer

If MsgBox("Do you want to delete this customer?" & vbCrLf & _
vbCrLf & _
"This will remove this customer" & vbCrLf & _
"You can NOT undo this!", vbCritical + vbYesNoCancel, "Delete
Customerr") = vbYes Then
Me.Undo
If IsNull(Me.ID) = False Then
strSql = "delete * from tblCustomer where id = " & Me.ID
CurrentDb.Execute strSql
endif
End If
DoCmd.Close acForm, Me.Name
End If

End Function

So, the above code will delete the record you are viewing..and I also have
the above to close the form.

You then in your menu bar, simply place the name of the above function in
the "on action" setting the of menu, so:

=MyDelete()

Thus, the above is all you need. As side note, you do NOT want to qualify
the form, and function names with a full pathname like:

forms!frmMyCusttomer.MyDelete()

Just use the function name:

=MyDelete()

Also, the real nice feature of this is in fact that you can make a
consistent function name to "delete" and each form can thus have a public
function called MyDelete(). This means in effect that you can make custom
menus that apply to more then one screen if you use a consistent function
name. Whatever form has the current focus will thus run the MyDelete()
function.
 
FANTASTIC!!!

You just made my scheduling calendar easily portable to other applications.

Thanks Much!

Judy
 
Back
Top