Access เขียนโปรแกรมป้อนข้อมูล
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 545   1
URL.หัวข้อ / URL
Access เขียนโปรแกรมป้อนข้อมูล

เขียนโปรแกรม ป้อนข้อมูลเข้า และมี field ประเภทที่ต้องการให้ ระบบ Auto number ให้อยากเขียน Function เพื่อ Auto Number จะต้องเริ่มยังไงครับ (โดยให้เช็คขอ้มูล Record
สุดท้ายของ Table ที่เก็บข้อมูลด้วย)




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

1 @R00011
ผมยกเอาตัวอย่างจริงมาให้ดูเลยนะครับ หลักการมีอยู่ว่า จะให้วิธี คลิก 2 ทีที่ Text Box ชื่อ itemno แล้วให้โปรแกรมไปดึง 3 ตัวอักษรแรกใน Combo Box ชื่อ cmbDiscipline (ใช้ในการแบ่งหมวดหมู่ของชื่อ itemno) มาประกอบเข้าเป็น 3 ตัวแรกของรหัสเป้าหมายด้วย จากนั้นให้เพิ่ม 000 เข้าไป แล้วไปตรวจหาหมายเลขสุดท้ายของรหัสที่มีในหมวดนี้ แล้วบวกด้วย 1 เข้าไป ถ้ายังไม่มีให้เริ่มที่หมายเลข 1 ศึกษาจากตัวอย่างข้างล่างดูนะครับ Private Sub itemno_DblClick(Cancel As Integer) Dim intMax As Integer 'ดูว่า Form เปิดอยู่ในโหมด Add หรือไม่ ถ้าไม่ใช่ให้หยุดการทำงาน If Me.DataEntry = False Then Exit Sub End If 'ตรวจดูว่าช่อง itemno ว่างอยู่หรือไม่ If IsNull(Me.itemno) Or Me.itemno = "" Then 'ดูว่าช่อง cmbDiscipline ว่างหรือไม่ If Not IsNull(Me.cmbDiscipline) Or Me.cmbDiscipline <> "" Then If IsNull(DMax("int(mid([itemno],4))", "tblEquipment", "left([itemno],3)= left(Forms!frmEquipment![cmbDiscipline],3)")) Then intMax = 1 Me.itemno = UCase(Left(Me.cmbDiscipline, 3)) & "000" & intMax Else intMax = DMax("int(mid([itemno],4))", "tblEquipment", "left([itemno],3)= left(Forms!frmEquipment![cmbDiscipline],3)") Me.itemno = UCase(Left(Me.cmbDiscipline, 3)) & "000" & intMax + 1 End If Else MsgBox "You have to select the discipline of the item first" Me.cmbDiscipline.SetFocus End If End If End Sub Good luck!
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.1371s