ให้ระบบมีการตรวจสอบข้อมูลก่อนการบันทึก
Posted: Fri Apr 08, 2022 11:39 am
เรียน อาจารย์
ก่อนการบันทึกข้อมูล จะให้ระบบมีการตรวจสอบ Date of Surgery, Room และ Time of Surgery ที่กรอกในช่อง B5,B6,B7 หากมีใน Sheet "Data" แล้วจะมีข้อความขึ้น "มีการจองข้อมูลในห้อง วันและเวลาดังกล่าวแล้ว"
ต้องปรับ Code อย่างไรครับ ขอบคุณครับ
ก่อนการบันทึกข้อมูล จะให้ระบบมีการตรวจสอบ Date of Surgery, Room และ Time of Surgery ที่กรอกในช่อง B5,B6,B7 หากมีใน Sheet "Data" แล้วจะมีข้อความขึ้น "มีการจองข้อมูลในห้อง วันและเวลาดังกล่าวแล้ว"
ต้องปรับ Code อย่างไรครับ ขอบคุณครับ
Code: Select all
Sub Save()
Dim x As Integer
Dim r As Integer
If Sheets("sheet2").Columns("h:h").Find(Worksheets("sheet1").Range("B5") and Sheets("sheet2").Columns("I:I").Find(Worksheets("sheet1").Range("B6") and Sheets("sheet2").Columns("J:J").Find(Worksheets("sheet1").Range("B7")
Then
x = MsgBox("มีการจองข้อมูลในห้อง วันและเวลาดังกล่าวแล้ว??", vbOKCancel, "แจ้งเตือน")
else if
r = Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("Data").Cells(r, 1).Value = r - 1
Sheets("Data").Cells(r, 2).Value = Day(Date)
Sheets("Data").Cells(r, 3).Value = Month(Date)
Sheets("Data").Cells(r, 4).Value = Year(Date) - 2000
Sheets("Data").Cells(r, 5).Value = Sheets("Input").Range("B2").Value
Sheets("Data").Cells(r, 6).Value = Sheets("Input").Range("B3").Value
Sheets("Data").Cells(r, 7).Value = Sheets("Input").Range("B4").Value
Sheets("Data").Cells(r, 8).Value = Sheets("Input").Range("B5").Value
Sheets("Data").Cells(r, 9).Value = Sheets("Input").Range("B6").Value
Sheets("Data").Cells(r, 10).Value = Sheets("Input").Range("B7").Value
End If
End Sub