อยากให้เลขที่บิล auto Run ต่อจากเลขที่บิลของข้อมูลที่ป้อน

เริ่มโดย kunlek, 22 เม.ย 19 , 09:50:34

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

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

kunlek

ปกติเมื่อป้อนข้อมูลแต่ละวัน เลขที่บิลจะ auto running เป็น IV62-04-21-01 บิลต่อไปเป็น 02  03 ...ถ้าป้อนในวันเดียวกัน ครับ  แต่ถ้าวันนี้ต้องการกลับไปป้อนเอกสารย้อนหลังเป็นวันที่ 5 เมษายน ประมาณ 10 บิล ต้องการให้เลขที่บิล กลับไป running  IV62-04-05-01  ...02...03 ผมจะต้องแก้ตรงไหนครับ

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


strDate = "IV" & "" & (Format(DATE, "yy-mm-dd"))

If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],12))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If

End Sub

Private Sub Text185_Enter()
'Private Sub bill_no_Enter()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String


strDate = "IV" & "" & (Format(DATE, "yy-mm-dd"))

If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If

End Sub
  •  

kunlek

ใช่ครับกำหนด runningจาก date  และอย่างที่ถามว่าวันที่ 5 มีการใช้เลขที่ไปแล้ว  ผมก็ต้องการให้ running ต่อจากใบสุดท้ายของวันที่ 5  และใบต่อๆๆไปก็ต่อท้ายแต่อยู่ในกรุ๊ปวันที่ 5 คือ IV62-04-05-xx.... ประมาณนี้ครับ
  •  

ปิ่นณรงค์

อ้างถึงจาก: kunlek ใน 22 เม.ย 19 , 13:58:13
ใช่ครับกำหนด runningจาก date  และอย่างที่ถามว่าวันที่ 5 มีการใช้เลขที่ไปแล้ว  ผมก็ต้องการให้ running ต่อจากใบสุดท้ายของวันที่ 5  และใบต่อๆๆไปก็ต่อท้ายแต่อยู่ในกรุ๊ปวันที่ 5 คือ IV62-04-05-xx.... ประมาณนี้ครับ
งันลอง Copy Code ข้างบนไปรันดูครับ ว่าได้ไหม Backup ไว้ก่อนนะคับ
การกำหนดวัน ต้องมีวันที่อ้างอิง ครับ ที่ Form เก็บค่าวันที่ไว้ textbox ตัวไหนบ้างไหม เอา textbox ตัวนั้นละมาอ้างอิง
:love: :grin:
  •  

kunlek

ขึ้น compile error; syntax error   บรรทัดที่ 5ตรง if txt_date ..........
หมายความว่าผมต้องเพิ่ม ฟิลด์ txt_date ในฟอร์มด้วย หรือเปล่า หรือว่า txt_date ของอจ.คือ bill_date ที่ผมมีอยู่แล้ว ครับ
  •  

ปิ่นณรงค์

อ้างถึงจาก: kunlek ใน 22 เม.ย 19 , 14:27:02
ขึ้น compile error; syntax error   บรรทัดที่ 5ตรง if txt_date ..........
หมายความว่าผมต้องเพิ่ม ฟิลด์ txt_date ในฟอร์มด้วย หรือเปล่า หรือว่า txt_date ของอจ.คือ bill_date ที่ผมมีอยู่แล้ว ครับ

Private Sub Command0_Click()
Dim StrBill_Date As String
Dim StrtoDay As String
If Not IsNull(Me.Bill_date) Then
StrBill_Date = Format(Bill_date, "D/M/YYYY")
StrtoDay = Format(Now, "D/M/YYYY")
If StrBill_Date = StrtoDay Then
Call ForIsToday
Else
Call ForIsOtherday
End If
End If
End Sub

Sub ForIsToday()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String
strDate = "IV" & "" & (Format(Now, "yy-mm-dd"))
    If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],12))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If
End If
End Sub

Sub ForIsOtherday()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String
strDate = "IV" & "" & (Format(Bill_date, "yy-mm-dd"))
    If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],12))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If
End Sub



ผมแบ่งเป็น 2 Sub คือ
ForIsToday() ผมใช้การเปรียบเทียบวันที่ปัจจุบัน กับ Bill_date ครับ ถ้าวันที่เดียวกัน ก็จะใช้ Now() มาสร้าง เลขที่บิล

ForIsOtherday() เมื่อเช็คว่าวันที่ไม่ใช่วันปัจจุบัน ก็จะเอาวันที่ของ Bill_date มาสร้างเลขที่บิลครับ
ลองดูตัวอย่างด้านล่างนะครับ
:love: :grin:
  •  

kunlek

ขออภัยครับ ไฟล์ที่แนบมาใช้โปรแกรมอะไรเปิดครับ winr  หรือ winzip
  •  

ปิ่นณรงค์

:love: :grin:
  •  

kunlek

  •  

kunlek

ทำไมรวน เลขที่บิลไม่ running ย่ำอยู่กับเลขเดิม อจ.ช่วยกรุณาชี้จุดทีครับ  ผมทำตาราง voucher 1 ตางราง  แล้วสร้างฟอร์มบันบิล ทั้งขาย(IVปป-ดด-วว-xx)  ทั้งค่าใช้จ่าย(PAปป-ดด-วว-xx) ค่าใช้จ่ายไม่มี VAT (PANVปป-ดด-วว-xx) และมีการบันทึกบิลย้อนหลัง เดือน กพ เพราะไม่ได้บันทึกแบบวันต่อวัน *****ปัญหาคือเลขย่ำอยู่กับที่ครับแต่ รูปแบบบิลได้ครับ)

Private Sub Text89_Click()
Dim StrVoucher_date As String
Dim StrtoDay As String
If Not IsNull(Me.Voucher_date) Then
StrVoucher_date = Format(Voucher_date, "DD/MM/YY")
StrtoDay = Format(Now, "DD/MM/YY")
If StrVoucher_date = StrtoDay Then
Call ForIsToday
Else
Call ForIsOtherday
End If
End If
End Sub

Sub ForIsToday()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String
strDate = "PANV" & "" & (Format(Now, "yy-mm-dd"))
    If Me.voucher_id = "" Or IsNull(Me.voucher_id) Then
        If IsNull(DMax("Val(Mid([voucher_id],10))", "voucher", "Left([Voucher_id],10) = '" & strDate & " '")) Then
            Me.voucher_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([Voucher_Id],10))", "voucher", "Left([Voucher_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If
End If
End Sub

Sub ForIsOtherday()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String
strDate = "PANV" & "" & (Format(Voucher_date, "yy-mm-dd"))
    If Me.voucher_id = "" Or IsNull(Me.voucher_id) Then
        If IsNull(DMax("Val(Mid([Voucher_id],10))", "voucher", "Left([Voucher_id],10) = '" & strDate & " '")) Then
            Me.voucher_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([Voucher_Id],10))", "voucher", "Left([Voucher_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If
End Sub
  •  

kunlek

อยากจะให้มีคำสั่ง ไปต่อลำดับจากเลขที่มีอยู่แล้ว และกลุ่มใครกลุ่มมัน(กลุ่มในที่นี้หมายถึง ตัวอักษรขึ้นต้นครับ)
  •  

ปิ่นณรงค์

อ้างถึงจาก: kunlek ใน 02 พ.ค. 19 , 16:59:37
ทำไมรวน เลขที่บิลไม่ running ย่ำอยู่กับเลขเดิม อจ.ช่วยกรุณาชี้จุดทีครับ 

คุณต้องดูจาก ตัวอักษรที่ใช้อ้างถึงด้วยครับ
Fuction Mid ตัวอย่าง
https://www.techonthenet.com/access/functions/string/mid.php
Fuction Left คือนับจำนวนตัวอักษรจากทางซ้ายไปกี่ตัว ถ้ารหัสเป็น PANV62-05-02-01
Left 12 คือ PANV62-05-02 ครับ ส่วนที่เหลือ จะได้จาก INTMAX มา+1

ถ้า 2 หลัก แบบ IV Mid 12 Left 10
ถ้า 4 หลัก แบบ PANV Mid ต้อง 14 Left 12

แก้ใหม่ก็ได้แบบนี้
Private Sub Command0_Click()
Dim StrVoucher_date As String
Dim StrtoDay As String
If Not IsNull(Me.Voucher_date) Then
StrVoucher_date = Format(Voucher_date, "D/M/YY")
StrtoDay = Format(Now, "D/M/YY")
If StrVoucher_date = StrtoDay Then
Call ForIsToday
Else
Call ForIsOtherday
End If
End If
End Sub
Sub ForIsToday()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String
strDate = "PANV" & "" & (Format(Now, "yy-mm-dd"))
    If Me.voucher_id = "" Or IsNull(Me.voucher_id) Then
   
        If IsNull(DMax("Val(Mid([voucher_id],14))", "voucher", "Left([Voucher_id],12) = '" & strDate & " '")) Then
            Me.voucher_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([Voucher_Id],14))", "voucher", "Left([Voucher_id],12) = '" & strDate & " '")
                       intMax = intMax + 1
            Me.voucher_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If
End If
End Sub

Sub ForIsOtherday()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String
strDate = "PANV" & "" & (Format(Voucher_date, "yy-mm-dd"))
    If Me.voucher_id = "" Or IsNull(Me.voucher_id) Then
          If IsNull(DMax("Val(Mid([voucher_id],14))", "voucher", "Left([Voucher_id],12) = '" & strDate & " '")) Then
            Me.voucher_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([Voucher_Id],14))", "voucher", "Left([Voucher_id],12) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If
End Sub

:love: :grin:
  •  

kunlek

ได้แล้วครับ ขอบพระคุณครับ ผมสงสัย2 บรรทัดนี้ทำไมไม่ใช้  DD/MM/YY  เพราะเราใช้ short date
StrVoucher_date = Format(Voucher_date, "D/M/YY")
StrtoDay = Format(Now, "D/M/YY")
  •  

ปิ่นณรงค์

ตรงนี้แค่สร้างตัวแปลมาตรวจสอบ ครับ กำหนด Format วันที่แบบไหนก็ได้คับอะไรก็ได้ครับ ขอแค่ให้หมือนกัน จะใช้ DD/MM/YY ก็ได้เหมือนกันคับ

:love: :grin:
  •  

kunlek

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


strDate = "IV2" & "" & (Format(date, "yy-mm-dd"))

If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],13))", "voucher_s", "Left([voucher_s_id],11) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],13))", "voucher_s", "Left([voucher_s_id],11) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If

End Sub
Sub ForIsOtherday()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String
strDate = "IV2" & "" & (Format(date_sale, "yy-mm-dd"))
    If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],12))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],12))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If
End Sub

Private Sub Text185_Enter()
'Private Sub bill_no_Enter()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String


strDate = "IV2" & "" & (Format(date, "yy-mm-dd"))

If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],12))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],12))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If

End Sub

Private Sub voucher_s_id_BeforeUpdate(Cancel As Integer)

End Sub

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


strDate = "IV2" & "" & (Format(date, "yy-mm-dd"))

If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If

End Sub

Private Sub voucher_s_id_Enter()
'Private Sub bill_no_Enter()
Dim strDate As String
Dim intNum As Integer, intMax As Integer
Dim strSuffix As String


strDate = "IV2" & "" & (Format(date, "yy-mm-dd"))

If Me.voucher_s_id = "" Or IsNull(Me.voucher_s_id) Then
        If IsNull(DMax("Val(Mid([voucher_s_id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")) Then
            Me.voucher_s_id = strDate & "-" & "01"
            Debug.Print "1"
        Else
            intMax = DMax("Val(Mid([voucher_s_Id],10))", "voucher_s", "Left([voucher_s_id],10) = '" & strDate & " '")
            intMax = intMax + 1
            Me.voucher_s_id = strDate & "-" & Format(intMax, "00")
            Debug.Print "1"
        End If

End If

End Sub
************
เพิ่มเงื่อนไข
จาก code นี้เลขบิลที่ได้จาก voucher_s_id จะเป็น  IV2YY-MM-DD-01   รันนิ่ง 02..03..  อ้างอิงตาม date_sale
เรียน อจ จะเพิ่มโค๊ด "กดปุ่ม" ถามว่าเป็น  สำนักงานใหญ่ (เลข 1) หรือสาขา (เลข 2) ถ้าเป็น สำนักงานใหญ่ เลขที่บิล จะเป็นชุด IV1YY-MM-DD-01 ถ้าเป็นสาขา เลขที่บิล จะเป็นชุด IV2YY-MM-DD-01 
  •  

UnKnown

แนวทางคือกำหนดค่าตัวแปลเมื่อเลือกสาขา เช่น สำนักงานใหญ่ branch=1 , สาขา branch=2 เป็นต้น
แล้วก็นำเข้าไปใส่ในตัวแปลท่าน เช่น strDate = "IV" & branch & "" & (Format(date, "yy-mm-dd"))
ลองทดสอบดูครับ

https://www.thai-access.com/index.php?topic=1063.msg4744#msg4744
:ninja:     ลองคิด,ลองทำแนวคนไม่เก่งแอคเซส
หมายเหตุ เพื่อความปลอดภัยโปรดสำรองข้อมูลใว้ก่อนการแก้ไข
  •  

kunlek

  •  

kunlek

ต้องการให้ printout ทางเครืองพิมพ์ ต้นฉบับ=1 แผ่น   สำเนา=2 ฉบับ แต่ code นี้ กลายเป็น ต้นฉบับ=2  สำเนา=1 ฉบับ  ผิดตรงไหนไม่ทราบ
    sql = "SELECT [Forms]![ACC_????????????]![text185] AS voucher_s_id INTO printbill;"
   DoCmd.RunSQL sql
   Filename = DLookup("voucher_s_id", "printbill") & " m"
    FilePath = "d:\bills-stmitsu\INV\" & Filename & ".pdf"
    DoCmd.OpenReport "ใบกำกับขาย-ต้นฉบับ", acViewPreview, Filename
    DoCmd.OutputTo acOutputReport, "ใบกำกับขาย-ต้นฉบับ", acFormatPDF, FilePath
    DoCmd.PrintOut , , , , 1
    sql = "SELECT [Forms]![ACC_บันทึกการขาย]![text185] AS voucher_s_id INTO printbill;"
   DoCmd.RunSQL sql
   Filename1 = DLookup("voucher_s_id", "printbill") & " c"
    FilePath = "d:\bills-stmitsu\INV\" & Filename1 & ".pdf"
     DoCmd.OutputTo acOutputReport, "ใบกำกับขาย-สำเนา", acFormatPDF, FilePath
    DoCmd.PrintOut , , , , 2
Command285_DblClick_Exit:
    Exit Sub
  •  

UnKnown

ติดตรงที่สั่งดูตัวอย่างต้นฉบับคาใว้อยู่หรือเปล่าน้ออ  :question:  ลองปิดแล้วเทสดูครับ
DoCmd.OpenReport "ใบกำกับขาย-ต้นฉบับ", acViewPreview, Filename
:ninja:     ลองคิด,ลองทำแนวคนไม่เก่งแอคเซส
หมายเหตุ เพื่อความปลอดภัยโปรดสำรองข้อมูลใว้ก่อนการแก้ไข
  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: pattaya48150