คำสั่ง print report ที่ต่างภาษากัน ทำอย่างไรค่ะ
กระทู้เก่าบอร์ด อ.Yeadram

 18,790   68
URL.หัวข้อ / URL
คำสั่ง print report ที่ต่างภาษากัน ทำอย่างไรค่ะ

รบกวนท่านอาจารย์และท่านผู้รู้หน่อยค่ะ พอดีมีลูกค้า 2 ประเภท คือ ใช้ บิลภาษาไทย กับภาษา อังกฤษ ค่ะ เวลา ปริ้น รีพอท จึงต้อง สั่งปริ้น ตามแบบของลูกค้า ลองใช้ คำสั่ง dlookup ไป ก็ยังไม่สามารถทำได้ ค่ะ รบกวนท่านผู้รู้ช่วยแก้ได้ไหมค่ะ

function ที่หนูพยายามเขียน ประมาณนี้ค่ะ แค่ทำยังไงๆ โปรแกรม ก็ ปริ้นแต่รีพอท ภาษาไทย

Function PrintInvoice(OrderID As Long) As Boolean
Dim Result
Result = DLookup("[Language]", "Customers", "Language")
     If Result = "TH" Then
    DoCmd.OpenReport "InvoiceTH", acViewPreview, , "[Order ID]=" & OrderID, acDialog
    Else
    DoCmd.OpenReport "InvoiceEN", acViewPreview, , "[Order ID]=" & OrderID, acDialog
    End If
End Function

รบกวนหน่อยนะค่ะ

68 Reply in this Topic. Dispaly 4 pages and you are on page number 2

21 @R13250
คุณสันติสุขคะ จากคำถามข้างบนหนูมีรูปประกอบนะคะ สองปุ่มที่หนูวงกลมไว้คือหนูอยากให้เวลาคลิกแล้วถามPasswordก่อนที่จะคลิกเข้าไปได้อะค่ะ

22 @R13251
เรื่องการกำหนดสิทธิ์ มีการทำได้ 2 อย่างคือให้ Access จัดการให้เอง แต่เนื่องจากมันกำหนดได้ไม่กว้าง ผมจึงไม่ได้ใช้และไม่ได้ศึกษาในรายละเอียดต่อไปว่าจะต้องทำยังไง   อีกวิธีที่ผมใช้คือการสร้างระบบการเช็คสิทธิ์เอาเอง โดยสร้างเทเบิล เอาคร่าวๆว่า ฟอร์มอะไร ใครมีสิทธิ์ สิทธิ์ในการทำอะไร เมื่อผู้ใช้จะกระทำสิ่งที่ขึ้นกับสิทธิ์ ก็เช็คว่ามีสิทธิ์จริงหรือไม่ ระบบผมไม่ได้ทำถึงว่าต้องใส่ password ทุกครั้งที่จะกระทำ แต่ใส่ครั้งเดียวตั้งแต่ล็อคอินเข้าระบบ

เทเบิล (T) ก็มีฟิลด์
ชื่อฟอร์ม (F) เป็น string     เช่น frmProduct
รหัสผู้มีสิทธิ์ (U) เป็น string     เช่น SOMCHAI
สิทธิ์ (P) เป็น string    เช่น Open, Edit, Add, Delete

โค้ดก็สั้นๆแค่
If IsNull(Dlookup("F","T", "F = '" & Me.Name & "' and U = '" & ชื่อตัวแปรที่เก็บรหัสผู้ใช้ & "' and P = 'สิทธิ์ที่เราต้องการตรวจสอบ')) Then
    ' ไม่มีสิทธิ์ จะแสดงข้อความเตือนหรือจะทำอะไรต่อไปก็กำหนดตรงนี้
    ' อาจเป็น Exit Sub หรือ Goto บรรทัดที่เป็นจุดที่ออกจาก sub procedure
End If

ทีนี้ก็ใส่โค้ดนี้ไว้ที่ event procedure ที่เกิดเมื่อผู้ใช้จะกระทำสิ่งที่ต้องตรวจสอบสิทธิ์ สำหรับกรณีเป็น Bound Form ก็มีเช่น
- ใน Form_Open event procedure เพื่อ ตรวจสอบว่ามีสิทธิ์ใช้ฟอร์มนี้หรือไม่
- ใน Form_BeforeInsert event procedure เพื่อ ตรวจสอบว่ามีสิทธิ์เพิ่มเรคอร์ดหรือไม่
- ใน Form_Dirty event procedure เพื่อ ตรวจสอบว่ามีสิทธิ์ในการแก้ไขเรคอร์ดหรือไม่
- ใน Form_Delete event procedure เพื่อ ตรวจสอบว่ามีสิทธิ์ในการลบเรคอร์ดหรือไม่

ตัวอย่าง
Private Sub Form_Open(Cancel As Integer)
    If IsNull(Dlookup("F","T", "F = '" & Me.Name & "' and U = '" & strUserID & "' and P = 'Open')) Then
        Cancel = True
        Msgbox "คุณไม่มีสิทธิ์ใช้ฟอร์มนี้"
        Exit Sub
    End If
End Sub

ส่วนหน้าจอล็อคอินก็มีถามเยอะแล้ว ลองไปหากระทู้เก่าๆดูครับ
23 @R13253
เย้ๆ ขอบพระคุณค่ะ หนูกำลังนำโค้ดไปทำค่ะ
24 @R13262
หนูเขียน code login ออกมาแบบนี้อะค่ะ

ในตารางEmployees มี ฟิล username1 กับ password เรียบร้อยส่วน ตรงฟอร์มlogin ก็มีช่องที่เอาไว้พิมuser ชื่อว่า text33 และช่องพิมpasswordชื่อว่า text 31 แต่พอคลิกlogin แล้วมันก็ไม่ไปหน้า Home อะค่ะ เลยไม่ทราบว่าcodeผิดตรงไหนหรือเปล่ารบกวนอาจารย์แนะนำหน่อยนะคะ

Option Compare Database

Private Sub cmdLogin_Click()
Dim strUser As String
Dim strPWD As String


strUser = Me.Text33
If DCount("[Password]", "Employees", "[Username1]='" & Me.Text33 & "'") > 0 Then
    strPWD = DLookup("[Password]", "Employees", "[Username1]='" & Me.Text33 & "'")
    If strPWD = Me.Text31 Then
      DoCmd.Close acForm, "Home", acSaveNo
    End If
End If
        End Sub
25 @R13266
Private Sub cmdLogin_Click()
    Dim strPWD As Variant

    strPWD = DLookup("[Password]", "Employees", "[Username1]='" & Me.Text33 & "'")
    If Nz(strPWD,"") = Me.Text31 Then
       DoCmd.OpenForm "Home"
    End If
End Sub

26 @R13274
ทำตามcodeคุณสันติสุขแล้วLoginได้เรียบร้อยแล้วค่ะ ขอบพระคุณมากๆอีกครั้งนะคะแต่ติดอีกนิดเดียวค่ะ คือพอหนูกดLog in แล้วform home ขึ้น แต่หน้าLog in ไม่ปิดไปอะค่ะ ต้องเพิ่มตรงไหนให้formปิดไปอะค่ะ อาจารย์ :(
27 @R13275
Private Sub cmdLogin_Click()
    Dim strPWD As Variant

    strPWD = DLookup("[Password]", "Employees", "[Username1]='" & Me.Text33 & "'")
    If Nz(strPWD,"") = Me.Text31 Then
       DoCmd.OpenForm "Home"
       DoCmd.Close acForm, Me.Name
    End If
End Sub
28 @R13276
หนูทำได้แล้วค่ะหนูเพิ่ม DoCmd.Close เข้าไป แล้วมันก็ปิด เย้
29 @R13278
คุณสันติสุขคะ หนูยังทำภาษาไม่ได้เลยค่ะตอนนี้ในForm Customer Detail ที่เวลาคลิกที่ปุ่มCreateInvoiceในformเป็นแบบนี้อะค่ะ

Private Sub cmdCreateInvoice_Click()
    Dim OrderID As Long
    Dim InvoiceID As Long

    OrderID = Nz(Me![Order ID], 0)
    
    ' Gracefully exit if invoice already created
    If CustomerOrders.IsInvoiced(OrderID) Then
        If MsgBoxYesNo(OrderAlreadyInvoiced) Then
            CustomerOrders.PrintInvoice OrderID
        End If
    ElseIf ValidateOrder(Invoiced_CustomerOrder) Then
       
        ' Create Invoice Record
        If CustomerOrders.CreateInvoice(OrderID, 0, InvoiceID) Then
            
            ' Mark all Order Items Invoiced
            ' Need to change Inventory Status to SOLD from HOLD
            Dim rsw As New RecordsetWrapper
            With rsw.GetRecordsetClone(Me.sbfOrderDetails.Form.Recordset)
               While Not .EOF
                    If Not IsNull(![Inventory ID]) And ![Status ID] = OnHold_OrderItemStatus Then
                        rsw.Edit
                        ![Status ID] = Invoiced_OrderItemStatus
                        rsw.Update
                        Inventory.HoldToSold ![Inventory ID]
                    End If
                    rsw.MoveNext
               Wend
            End With
            
            ' Print the Invoice
            CustomerOrders.PrintInvoice OrderID
       
            SetFormState
        End If
    End If
End Sub



แต่ตัวFunctionหนูเอาไปวางไว้ที่ มอดูล ที่ชื่อว่าCustomerOrder ซึ่งรายละเอียดตั้งแต่CreateInvoiceคือ

Function CreateInvoice(OrderID As Long, Amt As Currency, InvoiceID As Long) As Boolean
    Dim rsw As New RecordsetWrapper
    If rsw.OpenRecordset("Invoices") Then
        With rsw.Recordset
            If Not rsw.AddNew Then Exit Function
            ![Order ID] = OrderID
            ![Amount Due] = Amt
            If rsw.Update Then
               .Bookmark = .LastModified
               InvoiceID = ![Invoice ID]
               CreateInvoice = True
            End If
        End With
    End If
End Function

Function IsInvoiced(OrderID As Long) As Boolean
    IsInvoiced = DCountWrapper("[Invoice ID]", "Invoices", "[Order ID]=" & OrderID) > 0
End Function

Function PrintInvoice(OrderID As Long) As Boolean
Dim Result
Result = DLookup("Language", "Customers", "ID='" & Me.CustomerID & "'")
If Result = "TH" Then
DoCmd.OpenReport "InvoiceTH", acViewPreview, , "[Order ID]=" & OrderID, acDialog
Else
DoCmd.OpenReport "InvoiceEN", acViewPreview, , "[Order ID]=" & OrderID, acDialog
End If
End Function

และอย่างที่่คุณสันติสุขบอกว่า Me. ต้องใช้กับForm แล้วในกรณีนี้หนูจะต้องแก้ส่วนนี้เป็นยังไงคะ หนูพยายามมาสักพักแล้วทำไงก็ออกมาไม่ตามFunctionเลยค่ะ ขอรบกวนกวนท่านอาจารย์ด้วยนะคะ

ขอบพระคุณมากค่ะ
30 @R13286
ก็ทำตามที่ผมตอบในข้อ 2. ของคำตอบ (R13177) แหล่ะครับ "ดังนั้นต้องเอาฟังก์ชั่น PrintInvoice ใส่เข้าไปในโมดูลของฟอร์มครับ หรือไม่ก็ต้องเพิ่มอากิวเมนท์ที่ส่งค่าของ CustomerID เข้ามายังฟังก์ชั่นนี้แทน"

สมมติว่าเราทำตามวิธีหลัง ตัวฟังก์ชั่นก็จะเป็น

Function PrintInvoice(CustomerID As String, OrderID As Long) As Boolean
Dim Result
Result = DLookup("Language", "Customers", "ID='" & CustomerID & "'")
...
...
...

ส่วนของโค้ดที่เรียกการพิมพ์ จากเดิม CustomerOrders.PrintInvoice OrderID ก็ต้องแก้เป็น CustomerOrders.PrintInvoice Me.CustomerID, OrderID
31 @R13301
ท่านอาจารย์คะตัวภาษาหนูทำได้แล้วค่ะ ขอบพระคุณมากๆเลยนะคะ ตอนนี้เหลือปัญหาสุดท้ายแล้วค่ะ ถ้าทำตรงนี้ได้ โปรแกรมก็จะถูกนำไปใช้งานจริงแล้วซึ่งหนูจะดีใจมากๆเลยค่ะ

ปัญหามีอยู่ว่า เอาเป็นข้อมูลคร่าวๆก่อนนะคะ คือ สินค้าของหนูเป็นสินค้าประเภท น้ำตาลซอง,เกลือซอง,ไม้จิ้มฟันซอง ซึ่งราคาที่ขายให้ลูกค้าแต่ละที่ไม่เหมือนกันเพราะราคาจะขึ้นอยู่กับแบบของลูกค้าด้วย ซึ่งเรามีการพิมLOGOของลูกค้าลงไปที่ซอง เพราะฉะนั้น เวลาหนู ADD product ก็จะทำตามรูปแรกที่ แนปไปนะคะ คือ เลือก Company แล้วก็เลือกProduct ซึ่งหนูสร้างตารางที่ใส่ข้อมูลProduct ที่เป็นStandardไว้ และหนูมาแยกความต่างที่ ProductCode ซึ่งจะใส่ชื่อบริษัทไว้ข้างหน้า รบกวนอาจารย์ดูที่รูปนะคะ

คำถามข้อ1 มีวิธีไหนไหมค่ะที่พอเวลาหนูเลือกCompamyแล้วชื่อCompanyจะถูกcopy มาขึ้นที่ProductCode และ เมื่อเลือกProduct ชื่อProduct ก็จะถูกCopy มาไว้ต่อจาก Company

32 @R13302
คำถามข้อที่2 เวลาเปิดInvoice อะค่ะ เนื่องจากถ้าadd product ของแต่ละบริษัทเข้าไปเป็นตัวๆก็จะทำให้มีProduct เยอะมากๆๆๆๆๆๆๆๆ พอเวลาเปิดInvoice ก็ต้องมาหาproducยาวเลย หนูเลยอยากเรียนถามคุณสันติสุขว่า พอมีทางไหมค่ะถ้าเมื่อหนูคลิกเลือกCompanyแล้ว สินค้าของCompanyนั้นก็จะขึ้นมา(ขึ้นมาเฉพาะของcompanyนั้นเลยอะค่ะ) ตามในรูปพอคลิกสยามธานี ก็อยากให้ขึ้นแค่สินค้าของสยามธานีเพราะตรงProductCode เราจะadd ชื่อCompanyไว้ข้างหน้าอยู่แล้ว

รบกวนคุณสันติสุขอีกทีนะคะ :)
33 @R13306
1. ปัญหามันมีว่าชื่อที่เก็บมีคำว่า "บริษัท" และ "จำกัด" อยู่ด้วย แต่จะมีเสมอไปทุกๆลูกค้าหรือไม่ ผมว่าไม่น่าจะเสมอไปนะครับ ถ้าเสมอไปก็ง่ายหน่อย แต่ถ้าไม่เสมอไป วิธีแก้มี 2 แบบคือ เก็บในรูปแบบที่สามารถรู้ได้แน่นอนว่าตรงไหนเป็นชื่อเท่านั้น (ไม่รวมคำว่า "บริษัท" และ "จำกัด") เช่น "ธาราทิพิย์ จำกัด, บริษัท" หรือ "บริษัท [ธาราทิพย์] จำกัด" วิธีแรกนี้มีข้อเสียคือเมื่อใดที่ต้องการแสดงชื่อบริษัทเต็มๆที่ถูกต้องเป็น "บริษัท ธาราทิพย์ จำกัด" ก็จะต้องเขียนโปรแกรมเพื่อจัดการก่อนการแสดงหรือพิมพ์อีกที   ส่วนอีกวิธีคือ สร้างอีกฟิลด์นึงที่เก็บเฉพาะชื่อเดี่ยวๆ "ธาราทิพย์" เอาไว้   หลังจากเลือกได้แล้ว ก็จึงจะทำการต่อคำสำหรับ Product Code โดยใส่โค้ดใน AfterUpdate event procedure ของทั้งคอลโทรล Company และ ProductName เป็นในลักษณะ

Private Sub xxxxxx_AfterUpdate
     Me.ชื่อคอลโทรลของProductCode = Trim(nz(ชื่อที่ตัดมาได้จากฟิลด์ Company (ตามวิธีแรก) หรือชื่อคอลโทรลของอีกฟิลด์ที่เก็บชื่อเอาไว้ต่างหาก (ตามวิธีที่สอง), "") & " " & Nz(Me.ชื่อคอลโทรลของProductName, ""))
End Sub

ข้อ 2. ก็เหมือนกับคำถามประเภท เลือกจังหวัดแล้วแสดงอำเภอของจังหวัดนั้นๆ โดยใส่โค้ดไว้ใน AfterUpdate event procedure ของคอมโบบ็อกส์Customer เป็น

Private Sub xxxxxx_AfterUpdate
     Me.ชื่อsubform.form.ชื่อคอมโบบ็อกส์ของProduct.RowSource = "select ฟิลด์ต่างๆที่ต้องการแสดง from เทเบิลสินค้า where ชื่อฟิลด์ProductCode like * '" & ชื่อที่ตัดมาได้จากฟิลด์ Company (ตามวิธีแรก) หรือชื่อคอลโทรลของอีกฟิลด์ที่เก็บชื่อเอาไว้ต่างหาก (ตามวิธีที่สอง) & "'"
End Sub

และใส่ไว้ใน OnCurrent event procedure ของคอมโบบ็อกส์Customer เป็น

Private Sub xxxxxx_Current
     If Not Me.NewRecord Then
        (เหมือนข้างบน)
     End If
End Sub
34 @R13307
แก้ไขเป็น

like '*" & ชื่อที่ตัดมาได้จากฟิลด์ Company (ตามวิธีแรก) หรือชื่อคอลโทรลของอีกฟิลด์ที่เก็บชื่อเอาไว้ต่างหาก (ตามวิธีที่สอง) & "*'"
35 @R13324
รับทราบค่ะท่านอาจารย์ วันนี้หนูอยู่ข้างนอก กลับไปจะรีบนำโค้ดไปดำเนินการและจะรีบรายงานผลนะคะ ขอบพระคุณมากค่ะ :) :) :)
36 @R13444
ท่านอาจารย์คะ หนูเพิ่งกลับมาลุยต่อ ยังไม่ได้หายไปไหนนะคะ :)   
37 @R13457
ท่านอาจารย์คะ หนูมารายงานผล

ข้อที่ 1 เรื่องadd product หนูทำสำเร็จแล้วนะคะ ^^
ส่วนข้อที่ 2 ยัง งงๆ อยู่กำลังจัดการเรื่องcodeให้เข้าที่ค่ะ

มีเรื่องที่ 3 คือตรงกล่องcomboที่หาชื่อลูกค้า,สถาณที่ส่ง ที่หนูเคยถามคุณสันติสุขไปแล้ว แต่หนูอยากจะเพิ่มเติมตรงที่ว่าเวลาเรากดค้นหาอะค่ะตอนนี้มันจะค้นหาเฉพาะตัวอักษรแรก(ตามรูปนะคะ)นั้นหมายถึงเราต้องพิมคำค้นหาแบบตรงตามชื่อตั้งแต่แรกเลยแต่ถ้าหนูจะค้าหาคำอื่นๆที่เป็นคำตรงกลางหรือคำในช่องที่2คือ ชื่อสถาณที่ส่ง หรือ ช่องที่3 คือID กล่องก็ไม่หาให้หนูเลย ง่ายๆคือหนูอยากจะให้ค้นหาได้ทุกช่องทุกคำอะคะ :( ต้องแก้ไขตรงไหนหรือเปล่าคะ


หาเจอ


พิมชื่อหลัง หาไม่เจอเลยอะค่ะ
38 @R13458
ขอโทษค่ะอาจารย์ รูปซ้ำ รูปนี้คือรูปที่พิมแล้วหาเจอค่ะ
39 @R13459
SELECT [ID], [Company], [Address For Ship], [ID] FROM [Customers Extended] WHERE [ID]<>Nz(Form!ID,0) ORDER BY [Company], [Address For Ship];

ตอนนี้ใช้ code นี้ค่ะ
40 @R13460
อาจารย์คะ เรื่องที่ 2 หนู่ใส่codeตามที่อาจารบอกแล้วมันขึ้นerror แบบนี้


หนูไม่แน่ใจว่าใส่codeถูกจุดหรือเปล่าคะ
ส่วนนี้เป็น code


Option Compare Database
Option Explicit


Sub SetDefaultShippingAddress()
    If IsNull(Me![Customer ID]) Then
        ClearShippingAddress
    Else
       
        Dim rsw As New RecordsetWrapper
        If rsw.OpenRecordset("Customers Extended", "[ID] = " & Me.Customer_ID) Then
        Me.[InvoiceNO] = DMax("[InvoiceNumber]", "[Orders]") + 1
            With rsw.Recordset
               Me![Ship Name] = ![Contact Name]
               Me![Ship Address] = ![Address]
               End With
        End If
    End If
End Sub


Private Sub cmdDeleteOrder_Click()
    If IsNull(Me![Order ID]) Then
        Beep
    ElseIf Me![Status ID] = Shipped_CustomerOrder Or Me![Status ID] = Closed_CustomerOrder Then
        MsgBoxOKOnly CannotCancelShippedOrder
    ElseIf MsgBoxYesNo(CancelOrderConfirmPrompt) Then
        If CustomerOrders.Delete(Me![Order ID]) Then
            MsgBoxOKOnly CancelOrderSuccess
            eh.TryToCloseObject
        Else
            MsgBoxOKOnly CancelOrderFailure
        End If
    End If
End Sub


Private Sub cmdClearAddress_Click()
    ClearShippingAddress
End Sub


Private Sub ClearShippingAddress()
    Me![Ship Name] = Null
    Me![Ship Address] = Null
    Me![Ship City] = Null
    Me![Ship State/Province] = Null
    Me![Ship ZIP/Postal Code] = Null
    Me![Ship Country/Region] = Null
End Sub


Private Sub cmdCompleteOrder_Click()
    If Me![Status ID] <> Shipped_CustomerOrder Then
        MsgBoxOKOnly OrderMustBeShippedToClose
    ElseIf ValidateOrder(Closed_CustomerOrder) Then
        Me![Status ID] = Closed_CustomerOrder
        eh.TryToSaveRecord
        MsgBoxOKOnly OrderMarkedClosed
        SetFormState
    
    End If
End Sub


Private Sub cmdCreateInvoice_Click()
    Dim OrderID As Long
    Dim InvoiceID As Long

    OrderID = Nz(Me![Order ID], 0)
    
    ' Gracefully exit if invoice already created
    If CustomerOrders.IsInvoiced(OrderID) Then
        If MsgBoxYesNo(OrderAlreadyInvoiced) Then
       
        CustomerOrders.PrintInvoice Me.Customer_ID, OrderID
       
        End If
    ElseIf ValidateOrder(Invoiced_CustomerOrder) Then
       
        ' Create Invoice Record
        If CustomerOrders.CreateInvoice(OrderID, 0, InvoiceID) Then
            
            ' Mark all Order Items Invoiced
            ' Need to change Inventory Status to SOLD from HOLD
            Dim rsw As New RecordsetWrapper
            With rsw.GetRecordsetClone(Me.sbfOrderDetails.Form.Recordset)
               While Not .EOF
                    If Not IsNull(![Inventory ID]) And ![Status ID] = OnHold_OrderItemStatus Then
                        rsw.Edit
                        ![Status ID] = Invoiced_OrderItemStatus
                        rsw.Update
                        Inventory.HoldToSold ![Inventory ID]
                    End If
                    rsw.MoveNext
               Wend
            End With
            
            ' Print the Invoice
          CustomerOrders.PrintInvoice Me.Customer_ID, OrderID

       
            SetFormState
        End If
    End If
End Sub



Private Sub cmdShipOrder_Click()
    If Not CustomerOrders.IsInvoiced(Nz(Me![Order ID], 0)) Then
        MsgBoxOKOnly CannotShipNotInvoiced
    ElseIf Not ValidateShipping() Then
        MsgBoxOKOnly ShippingNotComplete
    Else
        Me![Status ID] = Shipped_CustomerOrder
    
        If IsNull(Me![Shipped Date]) Then
            Me![Shipped Date] = Date
        End If
        eh.TryToSaveRecord
        SetFormState
    End If
End Sub


Private Sub Customer_ID_AfterUpdate()
      Me.[Customer Orders Subform].Form.[Product ID].RowSource = "SELECT [ID], [Company], [Address For Ship], [ID] FROM [Customers Extended] WHERE [Product Code] like '*" & [Customer ID] & "*'"
    SetFormState False
    If Not IsNull(Me![Customer ID]) Then
        SetDefaultShippingAddress
    End If
End Sub
Private Sub Form_Current()
If Not Me.NewRecord Then
      Me.[Customer Orders Subform].Form.[Product ID].RowSource = "SELECT [ID], [Company], [Address For Ship], [ID] FROM [Customers Extended] WHERE [Product Code] like '*" & [Customer ID] & "*'"
    SetFormState
    End If
End Sub



Private Sub Form_Load()
    SetFormState
End Sub


Function GetDefaultSalesPersonID() As Long
    GetDefaultSalesPersonID = GetCurrentUserID()
End Function

Function ValidateShipping() As Boolean
   If Nz(Me![Shipping Fee]) = "" Then Exit Function
    ValidateShipping = True
End Function

Function ValidatePaymentInfo() As Boolean
    If IsNull(Me![Payment Type]) Then Exit Function
    If IsNull(Me![Paid Date]) Then Exit Function
    
    ValidatePaymentInfo = True
End Function


Sub SetFormState(Optional fChangeFocus As Boolean = True)
    If fChangeFocus Then Me.Customer_ID.SetFocus
    Dim Status As CustomerOrderStatusEnum
       
    Status = Nz(Me![Status ID], New_CustomerOrder)

    TabCtlOrderData.Enabled = Not IsNull(Me![Customer ID])
    Me.cmdCreateInvoice.Enabled = (Status = New_CustomerOrder)
    
    Me.cmdShipOrder.Enabled = (Status = New_CustomerOrder) Or (Status = Invoiced_CustomerOrder)
   
    Me.cmdDeleteOrder.Enabled = (Status = New_CustomerOrder) Or (Status = Invoiced_CustomerOrder)
    Me.cmdCompleteOrder.Enabled = (Status <> Closed_CustomerOrder)
    
    
    Me.[Order Details_Page].Enabled = (Status = New_CustomerOrder)
    Me.[Shipping Information_Page].Enabled = (Status = New_CustomerOrder)
    Me.[Payment Information_Page].Enabled = (Status <> Closed_CustomerOrder)
    
    Me.Customer_ID.Locked = (Status <> New_CustomerOrder)
    Me.Employee_ID.Locked = (Status <> New_CustomerOrder)
    Me.sbfOrderDetails.Locked = (Status <> New_CustomerOrder)

End Sub


Function ValidateOrder(Validation_OrderStatus As CustomerOrderStatusEnum) As Boolean
    If IsNull(Me![Customer ID]) Then
        MsgBoxOKOnly MustSpecifyCustomer
    ElseIf IsNull(Me![Employee ID]) Then
        MsgBoxOKOnly MustSpecifySalesPerson
    ElseIf Not ValidateShipping() Then
        MsgBoxOKOnly ShippingNotComplete
    Else
        If Validation_OrderStatus = Closed_CustomerOrder Then
            If Not ValidatePaymentInfo() Then
               MsgBoxOKOnly PaymentInfoNotComplete
               Exit Function
            End If
        End If

        Dim rsw As New RecordsetWrapper
        With rsw.GetRecordsetClone(Me.sbfOrderDetails.Form.Recordset)
            ' Check that we have at least one specified line items
            If .RecordCount = 0 Then
               MsgBoxOKOnly OrderDoesNotContainLineItems
            Else
               ' Check all that all line items have allocated inventory
               Dim LineItemCount As Integer
               Dim Status As OrderItemStatusEnum
               LineItemCount = 0
               While Not .EOF
                    
                    LineItemCount = LineItemCount + 1
                    Status = Nz(![Status ID], None_OrderItemStatus)
                    If Status <> OnHold_OrderItemStatus And Status <> Invoiced_OrderItemStatus Then
                        MsgBoxOKOnly MustBeAllocatedBeforeInvoicing
                        Exit Function
                    End If
                    rsw.MoveNext
               Wend
                                        
               ValidateOrder = True
            End If
        End With
    End If
End Function



Boxค้าหาcustomerชื่อ Customer ID
ฟิล product code ชื่อ product code
ฟิล ที่ต้องการให้ชื่อตรงกับproduct code คือ Company

เพราะตอนนี้ข้อแรกที่เป็น Product code ชื่อหน้าจะไม่เป็นชื่อตัดมาตามที่อาจารบอกนะคะ หนูใช้เป็นชื่อCompanyเลยซึ่งเวลาต่อคำตรงชื่อcompany มันกลายเป็นIDของลูกค้าแทนต่อด้วยชื่อสินค้าค่ะ

[IMG ]images/image-not-found.png[/IMG]

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