If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Command button code
I have many forms in my database that have the same buttons like save,
destroy, go to next. Do every form does to have it's 'own code'? I mean if instead of using commandbutton names with numbers I could create for instance Command_Destroy -button and use it everywhere. It just feels so stupid to make it in many forms all over again... -e- Sorry my stupid question |
#2
|
|||
|
|||
Command button code
You could have a public function to "SaveRecord()" for example, store it in
a general module and call it from every form's "Save" command button. Some application designs do this, but I suspect most folks use a handful of form templates with embedded code for the usual buttons. -Ed "elli" wrote in message ... I have many forms in my database that have the same buttons like save, destroy, go to next. Do every form does to have it's 'own code'? I mean if instead of using commandbutton names with numbers I could create for instance Command_Destroy -button and use it everywhere. It just feels so stupid to make it in many forms all over again... -e- Sorry my stupid question |
#3
|
|||
|
|||
Thanks
Thanks Ed
I'll startto look in to this Take care elli "Ed Robichaud" kirjoitti .. . You could have a public function to "SaveRecord()" for example, store it in a general module and call it from every form's "Save" command button. Some application designs do this, but I suspect most folks use a handful of form templates with embedded code for the usual buttons. -Ed "elli" wrote in message ... I have many forms in my database that have the same buttons like save, destroy, go to next. Do every form does to have it's 'own code'? I mean if instead of using commandbutton names with numbers I could create for instance Command_Destroy -button and use it everywhere. It just feels so stupid to make it in many forms all over again... -e- Sorry my stupid question |
#4
|
|||
|
|||
Command button code
I would say that 90% of my custom menu bars call, and run my VBA code.
All you need to do is make the code (a function) public, and then simply place the function name in the buttons on-action event code. Further, likely often you will have specific code to a particular form, and once again, you simply declare those functions (in that form) as public. The syntax to call the code then is: =YourFunctionName() Often, (if not most of the time), you code you call will need to pick up some information about he 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. Also, if the code you write is for the particular form, then as mentioned, you can simply place the code into the forms module code. There is no need to pick up the active screen...and you can use me. as you always used. If you want to see some sample menu bars, and why I use them, you can read the following: http://www.members.shaw.ca/AlbertKal...erFriendly.htm -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada http://www.members.shaw.ca/AlbertKallal |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Barcodes | Brandon Y | General Discussion | 6 | October 18th, 2005 07:28 PM |
Toolbars, Drop-Down Menus | Rick | New Users | 1 | September 21st, 2005 11:17 AM |
0x80040109 error when sending from SSL SMTP | krouse | General Discussion | 7 | March 15th, 2005 01:55 AM |
Excellent Navigation Method! | Bill Mitchell | Using Forms | 3 | December 16th, 2004 01:49 PM |
Attn Sprinks - clarification on VB code | babs | Using Forms | 6 | December 11th, 2004 12:55 AM |