เรียนอาจารย์สุภาพครับ
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 296   5
URL.หัวข้อ / URL
เรียนอาจารย์สุภาพครับ

ช่วยดูโค้ดให้หน่อยครับ ผมต้องการให้โชว์ Massage ในกรณีป้อนรหัสสินค้าซ้ำ ผมพยายามหลายครั้งแล้ว แต่ความสามารถไม่ถึงจริงๆ เลยต้องมารบกวนท่านอาจารย์ครับ ทั้งๆที่ทำตามตัวอย่างที่ดาวน์โหลดมา 
Option Compare Database 
Option Explicit 
Dim db As Database 
Dim rs1 As Recordset 
Dim rs2 As Recordset 
Dim rs3 As Recordset 
Dim rs4 As Recordset 
 
 
Private Sub cmbName_AfterUpdate() 
 
End Sub 
 
Private Sub cmbCustId_AfterUpdate() 
Dim strCust As String 
rs2.Seek "=", cmbCustId.Value 
If rs2.NoMatch = False Then 
    strCust = rs2.Fields("Cust_Name").Value & Space(5) & rs2.Fields("Cust_Surname").Value & _ 
    Space(5) & rs2.Fields("Cust_Address").Value & Space(5) & rs2.Fields("Cust_Telephone").Value 
    txtAddress.Value = strCust 
    txtDiscount.SetFocus 
Else 
    MsgBox "ไม่พบข้อมูลของรหัสที่คุณต้องการ", vbOKOnly, "ผลการทำงาน" 
    cmbCustId.SetFocus 
End If 
 
End Sub 
 
Private Sub Combo38_AfterUpdate() 
 
End Sub 
 
Private Sub cmbProductId_AfterUpdate() 
rs3.Seek "=", cmbProductId.Value 
If rs3.NoMatch = False Then 
    txtProductName.Value = rs3.Fields("Product_Name").Value 
    txtUnitPrice.Value = rs3.Fields("Unit_Price").Value 
    txtQuantity.SetFocus 
    Else 
   
    MsgBox " ไม่รหัสสินค้าที่คุณป้อน", vbOKOnly, "ข้อผิดพลาด" 
    cmbProductId.SetFocus 
End If 
 
     
     
     
End Sub 
 
 
 
Private Sub cmdSave_Click() 
If IsNull(cmbCustId) Or IsNull(cmbProductId) Or IsNull(txtQuantity) Or IsNull(txtDiscount) Then 
    MsgBox "คุณป้อนข้อมูลยังไม่ครบกรุณาตรวจสอบ", vbOKOnly + vbInformation, "คำเตือน" 
Else 
rs1.Seek "=", txtOrderId.Value 
If rs1.NoMatch Then 
    rs1.AddNew 
    rs1.Fields("Order_Id").Value = txtOrderId.Value 
    rs1.Fields("Order_Date").Value = txtdate.Value 
    rs1.Fields("Cust_Id").Value = cmbCustId.Value 
    rs1.Fields("Discount").Value = txtDiscount.Value 
    rs1.Update 
End If 
 
rs4.Seek "=", cmbProductId.Value 
If rs4.NoMatch Then 
    rs4.AddNew 
    rs4.Fields("Order_Id").Value = txtOrderId.Value 
    rs4.Fields("Product_Id").Value = cmbProductId.Value 
    rs4.Fields("Quantity").Value = txtQuantity.Value 
    rs4.Update 
    MsgBox "บันทึกข้อมูลเรียบร้อยแล้ว" 
Else 
    MsgBox "คุณป้อนรหัสสินค้าซ้ำ" 
       End If 
End If 
 
Me.QueryDetail.Requery 
 
End Sub 
 
    

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

1 @R00411
ผมว่าโค้ดที่เอามาให้ดูคงขาดส่วนที่ระบุว่าเป็น Recordset อันไหนครับ ซึ่งจะต้องมีส่วน Dim db As Database Dim rs1 As Recordset Dim rs2 As Recordset Dim rs3 As Recordset Dim rs4 As Recordset ... Set db = CurrentDb Set rs1 = db.Opendrecordset("ชื่อตารางหรือคิวรี") Set rs2 = db.Opendrecordset("ชื่อตารางหรือคิวรี") Set rs3 = db.Opendrecordset("ชื่อตารางหรือคิวรี") Set rs4 = db.Opendrecordset("ชื่อตารางหรือคิวรี") ไม่ทราบมีส่วนนี้หรือเปล่าครับ
2 @R00413
ขอพระคุณครับอาจารย์
3 @R00417
ลักษณะ Code เหมือนกับ File ตัวอย่างที่หน้า Download ของอาจารย์สุภาพเลยครับ (File "Project.mdb") ในฟอร์มบันทึกรายการขาย
4 @R00418
ใช่ครับพยามทำตามแต่ละขั้นตอนแล้ว ยังไม่สำเร็จ
5 @R00419
ไม่ทราบว่าได้มีการแก้ไขโค้ดหรือเปล่าครับ ผมได้ลองโปรแกรมนี้ดูแล้ว ถ้าลองเลือกรายการเดิม มันจะฟ้องว่ามีการเลือกรายการซ้ำ ให้ดูตรงบันทัดสีน้ำเงินครับ Private Sub cmdOK_Click() If IsNull(cboCustomerID.Value) Or IsNull(cboProductID.Value) Or IsNull(txtSalesAmt.Value) Then MsgBox "ท่านต้องกรอกข้อมูลต่าง ๆ ให้ครบถ้วน ก่อนที่จะคลิ๊กปุ่มตกลง" Else rs3.Seek "=", txtOrderID.Value If rs3.NoMatch Then rs3.AddNew rs3.Fields("OrderID").Value = txtOrderID.Value rs3.Fields("CustomerID").Value = cboCustomerID.Value rs3.Fields("OrderDate").Value = txtOrderDate.Value rs3.Update End If rs4.Seek "=", txtOrderID.Value, cboProductID.Value If rs4.NoMatch Then 'บันทึกรายการ rs4.AddNew rs4.Fields("OrderID").Value = txtOrderID.Value rs4.Fields("ProductID").Value = cboProductID.Value rs4.Fields("SalesAmt").Value = txtSalesAmt.Value rs4.Update 'ตัดสต๊อค rs2.Edit rs2.Fields("Stock").Value = rs2.Fields("Stock").Value - txtSalesAmt.Value rs2.Update MsgBox "บันทึกรายการ และตัดสต๊อคเรียบร้อยแล้ว" Else MsgBox "ท่านบันทึกรายการนี้ซ้ำ กรุณาตรวจสอบด้วย" End If End If cboProductID.Value = Null txtProductName.Value = Null txtUnitPrice.Value = Null txtStock.Value = Null txtUnitName.Value = Null txtSalesAmt.Value = Null If IsNull(cboCustomerID.Value) Then cboCustomerID.SetFocus Else cboProductID.SetFocus End If ChdDetail.Requery End Sub
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0559s