การเรียกใช้งานโปรแกรมจากฟอร์มใน Access

ผศ.(พิเศษ) ศักดา  ศักดิ์ศรีพาณิชย์
วิทยาลัยการสาธารณสุขสิรินธร จังหวัดพิษณุโลก
23  มิถุนายน 2550

            ขณะที่เราทำงานอยู่บนฟอร์ม  บางโอกาสเรามีความจำเป็นที่จะต้องเรียกโปรแกรมขึ้นมาใช้งานได้  เช่น  เรียก Notepad มาบันทึกข้อมูลชั่วคราว หรือเรียกเครื่องคิดเลขมาคำนวณตัวเลขบางอย่าง  ฯลฯ ซึ่งเราสามารถเรียกโปรแกรมต่าง ๆ เหล่านั้นขึ้นมาใช้งานได้  โดยการเรียกโปรแกรมมาใช้งานเราใช้คำสั่ง Call และ Shell Function

            จึงขอเสนอไวยากรณ์ของ Call และ Shell ดังนี้

Call Statement

            Syntax

                    [Call] name [argumentlist]

            ส่วนต่าง ๆ ไวยากรณ์ของ Call statement syntax อธิบายได้ดังนี้

Part Description
Call Optional.
name Required. Name of the procedure to call.
argumentlist Optional.

Shell Fucntion

            Syntax

                    Shell(pathname[,windowstyle])

            Windowstyle

                    มีค่าของ Argument ดังนี้

Constant Value Description
vbHide 0 Window is hidden and focus is passed to the hidden window. The vbHide constant is not applicable on Macintosh platforms.
vbNormalFocus 1 Window has focus and is restored to its original size and position.
vbMinimizedFocus 2 Window is displayed as an icon with focus.
vbMaximizedFocus 3 Window is maximized with focus.
vbNormalNoFocus 4 Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus 6 Window is displayed as an icon. The currently active window remains active.

ตัวอย่าง

                ตัวอย่าง 1 เรียก Notepad

Private Sub cmdNotepad_Click()
Dim stAppName As String
        stAppName = "C:\WINDOWS\system32\notepad.exe"
        Call Shell(stAppName, 1)
End Sub

 

ตัวอย่าง 2  เรียกเครื่องคิดเลข

Private Sub cmdCalc_Click()
    Dim stAppName As String
        stAppName = "C:\WINDOWS\system32\calc.exe"
        Call Shell(stAppName, 1)
End Sub

ไฟล์ตัวอย่าง

                คลิกดาวน์โหลด CallShell_ExMDB ไปดูกัน

                หวังว่า พอเป็นแนวทางได้นะครับ