37
ห้อง MS Access / : หากไฟล์เปิดอยู่ให้ปิดก่อน
« เมื่อ: 31 พ.ค. 62 , 14:53:50 »
เช็ค path จากตัวแปร sLink เลยก็ได้คับถ้าเปิดอยู่ก็สั่งปิดแล้ว Copy พอ Copy เสร็จสั่งลบไฟล์เก่าเลย
ตรง Reference เพิ่ม microsoft scripting runtime ด้วยนะครับ
ตรง Reference เพิ่ม microsoft scripting runtime ด้วยนะครับ
โค๊ด: [Select]
Dim sPath, sfilename, sLink, sCopyInto, myOutput As String
Dim fso As Object
Dim OpenDB As Object
Dim myFileOld As FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
sfilename = GetFileName
myOutput = Right(sfilename, Len(sfilename) - InStrRev(sfilename, "."))
sPath = GetFilePath
sLink = sPath & sfilename
sCopyInto = [Forms]![manHisInsu]![folderInsu] & "\" & [Forms]![manHisInsu]![Even2] & "." & myOutput 'แล้ว Copy File
fso.CopyFile sLink, sCopyInto
Set fso = Nothing
Set OpenDB = GetObject(sLink) 'สั่งปิดไฟล์ก่อน
OpenDB.Application.Quit
Set OpenDB = Nothing
Set myFileOld = New FileSystemObject 'สั่งลบไฟล์เดิม
myFileOld.DeleteFile sLink
Set myFileOld = Nothing
MsgBox ("บันทึกเรียบร้อยแล้ว"), vbInformation, "ผลการทำงาน"
Exit_Command33_Click:
Exit Sub
Err_Command33_Click:
MsgBox " ไฟลนี้อาจเปิดอยู่ ให้ปิดไฟล์นี้เสียก่อน"
Resume Exit_Command33_Click