กำหนด code autorun
กระทู้เก่าบอร์ด อ.Yeadram

 1,813   6
URL.หัวข้อ / URL
กำหนด code autorun

รบกวนสอบถามเรื่องการทำ autorun โดยมีข้อมูลดังนี้ค่ะ ต้องขอแจ้งสิ่งที่ต้องการก่อนนะคะ อยากได้เลขที่เอกสารดังนี้ค่ะ INT01-YYYYxxxx (3 ตัวแรก คือ Internal, 01 คือ Inhouse, YYYY คือ ปีปัจจุบัน, xxxx คือ running no )

Table ชื่อ PersonTrain มี feild : TR_NO เพื่อเก็บเลขที่เอกสาร และ Filed อื่น ๆ ที่เกี่ยวข้อง

Form rec_condition มี combo(Type), combo(SubType) เมื่อเลือก condition ที่ form นี้แล้ว ให้ TR_NO ที่ Form Rec_Training autorun no ตามรูปแบบ ข้างต้นค่ะ

รบกวนท่านผู้รู้ทุกท่านด้วยค่ะ ลองค้นหาแล้ว ก็ยังไม่ตรงความต้องการค่ะ

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

1 @R12225
control source
=Internal & Inhouse & "-" & Format(Date,"yyyy") & running no
2 @R12239
ต้องขออภัยค่ะ ที่ให้ข้อมูลคำถามไม่ครบถ้วน สิ่งที่ต้องการคือ &&&XX-YYYYxxxx
&&& คือ ประเภทของการอบรม (INT, EXT, OJL, OJG)
XX คือ ประเภทย่อย (01 : Oriantation, 02 : Competency, 03 : Inhouse)
YYYY คือ ปีปัจจุบัน
xxxx คือ running no

โดย ก่อนทำการบันทึกประวัติการอบรม ได้สร้าง Form1 เพื่อให้ user เลือกว่าจะบันทึกแบบใด ก่อน จากนั้นจึงไป เปิด Form2 เพื่อบันทึกประวัติการอบรมต่อไป

คำถามคือเราจะทำการดึงค่าจาด Form1 เพื่อมาสร้าง รหัสการบันทึกตามรูปแบบที่ต้องการได้อย่างไร รบกวนผู้รู้ช่วยด้วยค่ะ
3 @R12243
รบกวนด้วยค่ะ ค้นหาและพยายาม ปรับแต่งแล้ว แต่ยังทำงานไม่สมบูรณ์ ผลที่ได้ เป็นดังนี้ค่ะ

rec 1 > INT02-2012001
rec 2 > INT02-2012011

Dim intmax As Integer
Dim b As String
Dim f As Form_rec_tr_condition
Dim bk As String

b = Form_rec_tr_condition.Controls("Type_det")
c = Format(Date, "YYYY")
intmax = intmax + 1

Me.TR_NO = (DMax("Val(Mid([TR_NO],13))", "Personaltrain", "Left([TR_NO],5) = '" & b & "'"))

If Me.TR_NO = "" Or IsNull(Me.TR_NO) Then
    Me.TR_NO = b & "-" & c & Format(intmax, "001")
    Else
       
       bk = b & "-" & c & Format(intmax, "000") + 1
End If

รบกวนผู้เชี่ยวชาญช่วยหน่อยค่ะ
4 @R12619
ลองดูน่ะครับ Concept คือ
1. เลือก ประเภทการฝึกอบรม (INT, EXT, OJL, OJG)
2. เลือก ประเภทย่อย (01 : Oriantation, 02 : Competency 03 : Inhouse)
    หลังจากเลือกข้อ 2 มันจะ Auto Running No ให้
ตัวอย่าง ผมส่งไปไว้ที่ G-mail
User-name : accboard@gmail.com
Password   : accgmail
ลองเข้าไป Download ดูน่ะครับ
5 @R12620
ส่วน Code ตามด้านล่างนี้
Private Sub SubType_AfterUpdate()

Dim strPrefix As String, strPrefix1 As String, intMax As Integer

strPrefix1 = Format(Date, "yyyy")
strPrefix = Me.TypeOfTraining & Format([SubType], "00") & "-" & strPrefix1


If Me.TypeOfTraining = "" Or IsNull(Me.TypeOfTraining) Then
       
        MsgBox "You have to select Type Of Training first", vbOKOnly, "Type Of Training is blank"
        Me.TypeOfTraining.SetFocus
        Me.SubType = ""
        Exit Sub

Else

    If Me.RunningNo_Main <> "" Or IsNull(Me.RunningNo_Main) Then
        If Nz(DCount("RunningNo_Main", "Table1", "left(RunningNo_Main,10)='" & strPrefix & "'"), 0) = 0 Then
            Me.RunningNo_Main = strPrefix & "0001"
        Else
            intMax = DMax("Val(Mid(RunningNo_Main,11,4))", "Table1", "left(RunningNo_Main,10)='" & strPrefix & "'")
            Me.RunningNo_Main = strPrefix & Format(intMax + 1, "0000")
        End If
    End If

End If

Me.RunningNo_Main.SetFocus
DoCmd.RunCommand acCmdSaveRecord
Me.Refresh

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