Jumat, 23 Oktober 2015

RE: [MS_AccessPros] how to avoid repeating code?

 

I would create a public function in a standard module like the following which assumes ModelCode is a text field. Then add the function name to the On Dbl Click property:
On Dbl Click: =OpenModel()
 
Public Function OpenModel()
    Dim ctl As Control
    Dim strModel As String
    Set ctl = Screen.ActiveControl
    strModel = ctl.Value
    DoCmd.OpenForm "frm_ModelCodes", acNormal, , "[ModelCode] = '" & strModel & "'", , acDialog
End Function
 
You still need to add this to every property where needed but at least there is only one line to add and it's not in the VBA window.
 
Duane Hookom, MVP
MS Access
 

To: MS_Access_Professionals@yahoogroups.com
From: MS_Access_Professionals@yahoogroups.com
Date: Fri, 23 Oct 2015 12:15:44 -0700
Subject: [MS_AccessPros] how to avoid repeating code?



I designed a database which will serve automotive production line in some problems
so, many of my database forms contains a field "ModelCode"
now i repeated a code to open the "frm_ModelCodes" form when i double click the field "ModelCode" on each form

My request is
is it possible to avoid repeating this code in each form.
or
i need to know how to type a code in a module and call it from all forms to open "frm_ModelCodes" form.

your quick support will be highly appreciated.

Youssef



__._,_.___

Posted by: Duane Hookom <duanehookom@hotmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

.

__,_._,___

Tidak ada komentar:

Posting Komentar