Block out "File > Close" Function
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 253   1
URL.หัวข้อ / URL
Block out "File > Close" Function

มีคนถามไว้ที่ 
http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_97&Number=108184&page=0&view=collapsed&sb=5&o=7&fpart=1&vc=1&PHPSESSID= 
 
ดังนี้ 
I know it's the weekend. But can anybody please help me? If not, I can repost  
during the weekday again.  
 
I simply want to block out the option for the user to use the drop down menu with  
the "File > Close" command and the "File > Exit" command. Is there an easy  
way to do this. I want to keep the others, but just not these two. This is the short  
of it. 
 
Here's th long (if anyone wants to know.) A few weeks ago, a couple experts or  
genius' here gave me the code to prevent the user to close out of a running  
database by clicking the "X" on the upper right. This worked to perfection!!! This  
would force the user to click the 'Exit' button on the database form.  
 
However, I imagined myself as an operator to see what I would do. If in those  
shoes, I might start clicking everything. By clicking the 'File > Exit' command,  
this will make the entire database disappear, although it is really there. Once  
here, there is no way to shut the program off without shutting the power off. This  
is not good. 
 
So If I can figure out a way to eliminate the 'File > Close' command, I will be home free. 
 
Thanks in advance. 
 
สรุปคำถาม เขาต้องการที่จะ disable คำสั่ง Close และ Exit ในเมนู File ไม่ให้ทำงาน จะทำอย่างไร 
 
ผมได้ตอบเขาไปว่า 
 
วิธีที่ง่ายที่สุดในการกันไม่ให้ผู้ใช้คลิกออกจากโปรแกรมโดยใช้คำสั่งทั้งสอง คือการ set ให้ Modal และ PopUp properties ของฟอร์มนั้นให้เป็น YES ซึ่งจะทำให้ผู้ใช้ไม่สามารถคลิกอะไรนอกฟอร์มได้  
 
หรือไม่ก็ต้องสร้าง menu ขึ้นมาใช้เอง 
 
ผมคิดว่าสามารถที่จะกันไม่ให้คำสั่งทั้ง 2 ทำงานได้ แต่ผมยังไม่มีโค้ดนั้นอยู่ในมือตอนนี้ 
 
และอย่าลืมที่จะกำหนด Shortcut Menu property ของ form ให้เป็น NO ด้วย ไม่งั้นผู้ใช้สามารถออกทางช่องโหว่นี้ได้เช่นกัน  
 
จากนั้นผมได้มาค้นไฟล์ตัวอย่างเก่าๆ ซึ่งผมจำได้ว่าเคยเขียนโค้ดอย่างนี้อยู่ และได้เจอจริงๆ จึงได้ให้โค้ดเขาไปดังนี้ 
 
Private Sub Form_Close() 
DisableCommand True 
End Sub 
 
Private Sub Form_Load() 
DisableCommand False 
End Sub 
 
Function DisableCommand(bln As Boolean) 
 
Dim CBarMenu As CommandBar, CBarCtl As CommandBarPopup 
 
Set CBarMenu = CommandBars("Menu Bar") 
Set CBarCtl = CBarMenu.Controls("File") 
 
' Disable these commands 
CBarCtl.Controls("Close").Enabled = bln 
CBarCtl.CommandBar.Controls("Exit").Enabled = bln 
CBarCtl.CommandBar.Controls("New Database...").Enabled = bln 
CBarCtl.CommandBar.Controls("Open Database...").Enabled = bln 
 
End Function 
 
และยังพบว่า ยังต้องกันไม่ให้คำสั่ง Open Database... และ New Database.... ทำงานด้วย จึงจะกันได้สนิททุกประตู 
 
หรือใครเห็นว่ายังมีประตูอื่นๆ ที่สามารถออกได้อีกครับ โวยวายเข้ามาได้ครับ 
 
*** Edited by Supap Chaiya *** 20/4/2546 11:44:34

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R00571
ผมได้เรียนรู้การสร้างโค้ดข้างบนจาก http://support.microsoft.com/default.aspx?scid=kb;en-us;q160293 ครับ ลองเข้าไปศึกษาเพิ่มเติมนะครับ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0396s