running no ... Dmax()
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 273   3
URL.หัวข้อ / URL
running no ... Dmax()

เรียนอาจารย์สุภาพ
หนูจะทำ running number โดยมีเดือนกับปีเป็นส่วนประกอบด้วยค่ะ ลอง run ตาม code ที่อาจารย์แนะนำแล้วค่ะ แต่พอ run แล้วขึ้น error "data type mismatch in criteria expression"
ชื่อ table = Software Support และ field ID มี data type เป็น text ขนาด 11 digits
format เป็นดังนี้ S03-05-0001.........รบกวนตรวจสอบให้หน่อยค่ะ

Private Sub ID_Click()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String

strDate = Format(Date, "yy-mm")

If Me.ID = "" Or IsNull(Me.ID) Then
If IsNull(DMax("Val(Right([ID],4))", "Software Support", "left([ID],6) = '" & "S" & strDate & "'")) Then
Me.ID = "S" & strDate & "-" & "0001"
Debug.Print "1"
Else
intMax = DMax("Val(Right([ID],4))", "Software Support", "Left([ID],6) = '" & "S" & strDate & "'")
intMax = intMax + 1
Me.ID = "S" & strDate & "-" & Format(intMax, "0000")
Debug.Print "1"
End If

End If
End Sub

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

1 @R03128
ไม่ควรตั้งชื่อ Object ต่างๆ ให้มีช่องว่างครับ ไม่ว่าจะเป็น Tables, Queries, ...

เพราะจะทำให้เขียนโค้ดมีความยุ่งยาก

ถ้ามีแล้ว ก็ต้องใส่ [ ] ปิดด้วยครับ ดังนี้

If IsNull(DMax("Val(Right([ID], 4))", "[Software Support]", "left([ID], 6) = '" & "S" & strDate & "'")) Then
Me.ID = "S" & strDate & "-" & "0001"
Debug.Print "1"
Else
intMax = DMax("Val(Right([ID], 4))", "[Software Support]", "Left([ID], 6) = '" & "S" & strDate & "'")
intMax = intMax + 1
2 @R03129
"data type mismatch in criteria expression"

error ยังขึ้นเหมือนเดิมค่ะ ตรวจดูแล้วที่ criteria ก็ไม่มีอะไรผิดพลาดนะคะ ตอนนี้ใช้ access XP อยู่ค่ะ

"left([ID], 6) = '" & "S" & strDate & "'"
3 @R03130
น่าจะมี References บางตัวขาดไปครับ

ให้ค้นในเว็บบอร์ดด้วยคำว่า Missing ดูครับ จะมีวิธีแก้ไขบอกไว้

@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0635s