Module level SaveRecord Sub

  • Thread starter Thread starter Lorenzo
  • Start date Start date
L

Lorenzo

Hello, just for learning purpouses I am trying to figure out how can be
achived the following:

Let's say I have "n" forms in each of them I prompt the user to save the
current record with a button that has the code:

Private Sub cmdSalva_Click()
On Error GoTo Err_cmdSalva_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_cmdSalva_Click:
Exit Sub

Err_cmdSalva_Click:
MsgBox Err.Description
Resume Exit_cmdSalva_Click

End Sub


All is good but is there a way to put this sub into a module and call it
passing the current form as a parameter? In the code in the form I would
then just have:

Private Sub cmdSalva_Click()
call Save
End Sub

Does this make any sense? Am I getting anywhere? One more question what is
the difference between modules and class modules? If answer is too long a
link to a good resource is also appreciated
Thank you,
Lorenzo
 
Yes, you can create a function in a standard module, and call it from
multiple places. There are several advantages of doing something involves
this way, e.g. there is only one thing to maintain, and the answer will be
consistent, no matter where it is called from.

Use class modules when you need to create instances of things. Here's an
introductory article from Microsoft:
Introduction to Stand-Alone Class Module Programming
at:
http://support.microsoft.com/kb/209968/en-us

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

"Lorenzo"
 
I am such a nerd but I can't tell you how happy made me see popping that
msgBox from a Module...almost like a yes to a date (okay now I am lost...but
I said almost ok) anyway this is what I did simple but worked out:

In the module:
Public Sub Salva(frm As Form)
On Error GoTo Err_alva


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox (" You just saved the record ! ")
Exit_Salva:
Exit Sub

Err_alva:
MsgBox Err.Description
Resume Exit_Salva

End Sub

In the form
Private Sub cmdSalva_Click()

Call Salva(Me)

End Sub

Beside jokes is it all correct? Thanks for the class modules tip I will dig
further down. Compliments for your access tips, as I clear concepts and
improve skills I enjoy them more and more!

Lorenzo


"Lorenzo"
 
Back
Top