ใช้ Dmax รันเลขที่บิลแล้ว Error แก้อย่างไรให้ใช้ได้ครับผม

เริ่มโดย UnKnown, 01 พ.ย 19 , 16:23:13

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

UnKnown

ใช้ Dmax รันเลขที่บิลแล้ว Error แก้อย่างไรให้ใช้ได้ครับผม  :question:
รูปแบบเลขคือแนว QU62XX นะครับ

Private Sub cmd_QuNew_Click()
    If GetUserLocaleInfo(GetSystemDefaultLCID(), &H1009) <> 7 Then
       Me.txtDateTH = mYear([txtDate])
    ElseIf GetUserLocaleInfo(GetSystemDefaultLCID(), &H1009) = 7 Then
       Me.txtDateTH = bYear([txtDate])
    End If
'    Me.QU_No = AutoQuNo
    Me.QU_No = "QU" & Right([txtDateTH], 2) & Right("00" & DMax("[QU_No]", "[T_Quot v7]", "Left([QU_No],4) = 'QU' & Right([txtDateTH], 2)") + 1, 2)
    DoCmd.OpenForm "F_Quot v7 Edit"

End Sub
:ninja:     ลองคิด,ลองทำแนวคนไม่เก่งแอคเซส
หมายเหตุ เพื่อความปลอดภัยโปรดสำรองข้อมูลใว้ก่อนการแก้ไข
  •  

nonc31

Me.QU_No = "QU" & Right([txtDateTH], 2) & Right("00" & DMax("[QU_No]", "[T_Quot v7]", "Left([QU_No],4) = 'QU'") & Right([txtDateTH], 2) + 1, 2)

แค่ใส่เครื่องหมายผิดที่ครับ
  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: UnKnown

UnKnown

อ้างถึงจาก: nonc31 ใน 01 พ.ย 19 , 18:04:04
Me.QU_No = "QU" & Right([txtDateTH], 2) & Right("00" & DMax("[QU_No]", "[T_Quot v7]", "Left([QU_No],4) = 'QU'") & Right([txtDateTH], 2) + 1, 2)

แค่ใส่เครื่องหมายผิดที่ครับ
นำไปใช้แล้วเลขที่ออกจะเป็น QU6263 แบบตายตัวไม่บวกเพิ่มเลยครับ



จากที่ความต้องการคือ QU & YY & 00 = QU6201-QU62++ , QU6301-QU63++ นั้น
ตอนนี้นำไปแก้ให้แยกไปคำนวนต่างหากเป็นอันใช้ได้แล้วครับผม :yuush:
Private Sub cmd_QuNew_Click()
    If GetUserLocaleInfo(GetSystemDefaultLCID(), &H1009) <> 7 Then
       Me.txtDateTH = mYear([txtDate])
    ElseIf GetUserLocaleInfo(GetSystemDefaultLCID(), &H1009) = 7 Then
       Me.txtDateTH = bYear([txtDate])
    End If
    Me.QU_No = AutoQuNo
    DoCmd.OpenForm "F_Quot v7 Edit"
End Sub

Function AutoQuNo() As String
Dim X As Variant
Dim bk As String
        X = DMax("Right(QU_No,2)", "[T_Quot v7]", "Left([QU_No],4) = 'QU' & Right([txtDateTH], 2)")
        If IsNull(X) Then bk = 1 Else bk = X + 1
    AutoQuNo = "QU" & Right([txtDateTH], 2) & Format(bk, "00")
End Function


ขอบคุณ อ.yeadram แนวทางจากกระทู้ > https://www.thai-access.com/yeadram_view.php?topic_id=651
:ninja:     ลองคิด,ลองทำแนวคนไม่เก่งแอคเซส
หมายเหตุ เพื่อความปลอดภัยโปรดสำรองข้อมูลใว้ก่อนการแก้ไข
  •