กระทู้เก่าบอร์ด อ.Yeadram
68,147 91
URL.หัวข้อ /
URL
ถึงท่านอาจารย์ สันติสุข ค่ะ
คำถามต่อเนื่องนะคะอาจารย์ พอดีที่หนูหายไปหนูแอบไปรับปริญญามาค่ะ
ข้อที่ 1 เรื่องการค้นหาข้อมูลจากกล่องComboค่ะ
หนูได้นำ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.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
SetFormState False
If Not IsNull(Me![Customer ID]) Then
SetDefaultShippingAddress
End If
End Sub
Private Sub Customer_ID_Current()
If Not Me.NewRecord Then
Me.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
End If
End Sub
Private Sub Customer_ID_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Customer_ID.RowSource = "SELECT [ID], [Company], [Address For Ship], [ID] FROM [Customers Extended]where [Company], [Address For Ship], [ID] like '*" & Me.Customer_ID.Text & "*' order by [Company], [Address For Ship]"
Me.Customer_ID.Dropdown
End Sub
Private Sub Form_Current()
SetFormState
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
ผลที่ได้คือเวลาพิมหาแล้วขึ้นกล่องว่าเปล่าค่ะ
ข้อที่ 1 เรื่องการค้นหาข้อมูลจากกล่องComboค่ะ
หนูได้นำ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.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
SetFormState False
If Not IsNull(Me![Customer ID]) Then
SetDefaultShippingAddress
End If
End Sub
Private Sub Customer_ID_Current()
If Not Me.NewRecord Then
Me.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
End If
End Sub
Private Sub Customer_ID_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Customer_ID.RowSource = "SELECT [ID], [Company], [Address For Ship], [ID] FROM [Customers Extended]where [Company], [Address For Ship], [ID] like '*" & Me.Customer_ID.Text & "*' order by [Company], [Address For Ship]"
Me.Customer_ID.Dropdown
End Sub
Private Sub Form_Current()
SetFormState
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
ผลที่ได้คือเวลาพิมหาแล้วขึ้นกล่องว่าเปล่าค่ะ
91 Reply in this Topic. Dispaly 5 pages and you are on page number 3
42 @R13862
ตกลงช่อง [Product Code] ต้องการเป็นค่าจากช่องไหนรวมกันบ้างครับ
43 @R13863
Id ลูกค้า ต่อด้วย ชื่อสินค้าเหมือนเดิมค่ะ
ตรง UnitThai,UnitENg ให้โชว์ค่าที่รับมาจากproduct standard เท่านั้นค่ะ เอาไว้ print ออกที่รีพอทเฉยๆ ค่ะ ไม่ต้องมีUnit ต่อท้าย ที่ product code ค่ะอาจารย์
ขอบพระคุณค่ะ
ตรง UnitThai,UnitENg ให้โชว์ค่าที่รับมาจากproduct standard เท่านั้นค่ะ เอาไว้ print ออกที่รีพอทเฉยๆ ค่ะ ไม่ต้องมีUnit ต่อท้าย ที่ product code ค่ะอาจารย์
ขอบพระคุณค่ะ
44 @R13864
เช็คดูดีๆว่าในคอมโบบ็อกซ์ [Product Name] นั้น BoundColumn เป็น 1, ColumnCount เป็น 2 หรือไม่ ถ้าไม่ใช่ก็แก้ให้เป็นตามนี้ครับ
45 @R13865
ได้แล้วค่ะ เย้ๆๆๆๆๆๆ
ทำงานจริงได้แล้ว ขอบพระคุณท่านอาจารย์ มากๆ ค่ะ
ทำงานจริงได้แล้ว ขอบพระคุณท่านอาจารย์ มากๆ ค่ะ
46 @R13957
อาจารย์คะ รบกวนถามอีกนิดนึงค่ะ Function นี้
Me.[InvoiceNO] = DMax("[InvoiceNumber]", "[Orders]") + 1
อยากให้เลขที่รัน เริ่มด้วย 0000 ก่อน 4 ตัว ต้องเพิ่ม code ยังไงคะ
ขอบพระคุณค่ะ
ตอนนี้ เอาโปรแกรม มาใช้จริงแล้วนะคะ ดีใจมากค่ะ :)
Me.[InvoiceNO] = DMax("[InvoiceNumber]", "[Orders]") + 1
อยากให้เลขที่รัน เริ่มด้วย 0000 ก่อน 4 ตัว ต้องเพิ่ม code ยังไงคะ
ขอบพระคุณค่ะ
ตอนนี้ เอาโปรแกรม มาใช้จริงแล้วนะคะ ดีใจมากค่ะ :)
47 @R13958
1. เริ่มด้วย "0000" เสมอ เช่น ถ้าค่า DMax( ) ให้ผลออกมาเป็น 123 เลข InvoiceNo จะเป็น "0000100" หรือมีเพียงแค่ 4 หลักเสมอเป็น "0123" ?
2. และ InvoiceNo มีประเภทข้อมูลเป็นอะไร Numeric (Integer, Long) หรือเป็น Text ?
2. และ InvoiceNo มีประเภทข้อมูลเป็นอะไร Numeric (Integer, Long) หรือเป็น Text ?
48 @R13959
ถามใหม่
1. เริ่มด้วย "0000" เสมอ เช่น ถ้าค่า DMax( ) ให้ผลออกมาเป็น 123 เลข InvoiceNo จะเป็น "0000124" หรือมีเพียงแค่ 4 หลักเสมอเป็น "0124" ?
1. เริ่มด้วย "0000" เสมอ เช่น ถ้าค่า DMax( ) ให้ผลออกมาเป็น 123 เลข InvoiceNo จะเป็น "0000124" หรือมีเพียงแค่ 4 หลักเสมอเป็น "0124" ?
49 @R13963
มีเพียงแค่ 4 หลักเสมอเป็น "0124" ค่ะ และ ถ้าตัวเลขเพิ่มเป็นหลักหมื่น เลขยังจะรันต่อไหมค่ะ ?
50 @R13966
ตอนนี้ ใช้เป็น Number Long intege ค่ะหนูกำลังคิดว่า ถ้าใช้เป็น Text จะดีกว่าไหมคะ เผื่อในอนาคตอาจจะเปลี่ยนให้มีตัวอักษรนำหน้า เช่น A001 ประมาณนั้นค่ะ แต่ตอนนี้ run เป็น 00001 ไปก่อน ค่ะ
51 @R13967
ถ้าคิดว่าอนาคตจะเปลี่ยน ก็จงเปลี่ยนเสียตั้งแต่ตอนนี้ครับ โค้ดก็ใช้เป็น
Me.[InvoiceNO] = Format$(DMax(...) + 1, "0000")
Me.[InvoiceNO] = Format$(DMax(...) + 1, "0000")
52 @R13968
ตอนนี้ เอาโปรแกรม มาใช้จริงแล้วนะคะ ดีใจมากค่ะ :)
ดีใจด้วยครับ ผมคิดค่าปรึกษาแค่เท่ากับเงินเดือนคุณส้ม 3 เดือนก็พอ รวมกับโบนัสปลายปีที่จะได้เพราะงานชิ้นนี้ กับส่วนแบ่ง 0.1% ของรายได้สุทธิของบริษัทต่อปีก่อนหักภาษีก็พอแล้ว ไม่เอาอะไรมาก
ดีใจด้วยครับ ผมคิดค่าปรึกษาแค่เท่ากับเงินเดือนคุณส้ม 3 เดือนก็พอ รวมกับโบนัสปลายปีที่จะได้เพราะงานชิ้นนี้ กับส่วนแบ่ง 0.1% ของรายได้สุทธิของบริษัทต่อปีก่อนหักภาษีก็พอแล้ว ไม่เอาอะไรมาก
53 @R13973
5555
54 @R14665
อาจารย์คะหนูมีเรื่องรบกวนอีกแล้วค่ะ ตอนนี้มีปัญหาแล้วตรงการเลือกสินค้า สืบเนื่องจากที่หนูเคยปรึษาอาจารย์เรื่องการaddข้อมูลสินค้า ที่เวลาเลือกลูกค้าแล้วต่อจากนั้นเลือกสินค้า ก็จะขึ้นเป็น ชื่อลูกค้า + สินค้า แล้วพอเปิดบิล เวลาเราเลือกลูกค้า สินค้าของลูกค้าคนนั้นๆก็จะขึ้นมา แต่ว่าหนูได้ทำตามที่อาจารย์บอกมันบันทึกเป็นลักษณะของ id+ชื่อสินค้า หนูคิดว่าจะดูง่ายกว่า แต่ปรากฏว่า ถ้า id ลูกค้าเป็น 4 สินค้าจะไม่ขึ้นเฉพาะลูกค้าที่เป็น 4 แต่ขึ้นสินค้าของทุกคนที่มีเลข4 อยู่ ค่ะ เช่น 14,44 สินค้าของรหัวพวกนี้ก็จะขึ้นมาหมดเลย หนูจะสามารถแก้ไขได้ไหมค่ะ ว่าให้เฉพาะเจาะจงการค้นหาอะค่ะ อาจารย์
รูปค่ะ
(แบบตัวอย่าง id+ชื่อสินค้า)
(ตัวอย่างเวลาเปิดบิล นี่คือรหัสลูกค้า 7 ปรากฏว่าทุกอย่างที่ เป็น 7 ขึ้นมาหมดเลยค่ะ)
หรือวิธีที่ 2 คือหนูเอาชื่อลูกค้ามานำหน้าทั้งหมดเลยแล้วหน้าเปิดinvoice จะต้องเขียนcode ยังไงให้มันหากันเจอแบบถูกต้องคะ :(
(ตัวอย่างแบบมีชื่อนำหน้าหมดเลยค่ะ)
ขอรบกวนความอัจฉริยะของอาจารย์อีกทีนะคะพยายามหาวิธีแก้มาสักพักแล้วไม่รู้จะทำยังไงจริงๆค่ะ
รูปค่ะ
(แบบตัวอย่าง id+ชื่อสินค้า)
(ตัวอย่างเวลาเปิดบิล นี่คือรหัสลูกค้า 7 ปรากฏว่าทุกอย่างที่ เป็น 7 ขึ้นมาหมดเลยค่ะ)
หรือวิธีที่ 2 คือหนูเอาชื่อลูกค้ามานำหน้าทั้งหมดเลยแล้วหน้าเปิดinvoice จะต้องเขียนcode ยังไงให้มันหากันเจอแบบถูกต้องคะ :(
(ตัวอย่างแบบมีชื่อนำหน้าหมดเลยค่ะ)
ขอรบกวนความอัจฉริยะของอาจารย์อีกทีนะคะพยายามหาวิธีแก้มาสักพักแล้วไม่รู้จะทำยังไงจริงๆค่ะ
55 @R14666
เพราะผมจำรายละเอียดไม่ได้แล้วว่าเรามีโค้ดตรงไหนบ้างที่ไปเปลี่ยน RowSource ของคอมโบบ็กซ์ ProductID ในส่วนของ OrderDetails เอาโค้ดนั้นทั้ง procedure มาแสดงให้ดูหน่อยครับ
56 @R14668
Code Form Product detail ค่ะ
Option Compare Database
Private Sub Combo47_AfterUpdate()
Me.[Product Code] = Trim(Nz(Combo47, "") & " " & Nz(Me.[Product Name], ""))
Me.[Product Name] = Null
Me.[Product Code] = Null
Call SetProductNameByLanguage
End Sub
Private Sub Combo47_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Combo47.RowSource = "SELECT [ID], [Company], [Address For Ship],[Language],[Code] FROM [Customers Extended] where ([Company] like '*" & Me.Combo47.Text & "*') or ([Address For Ship] like '*" & Me.Combo47.Text & "*') or ([ID] like '*" & Me.Combo47.Text & "*') order by [Company], [Address For Ship];"
Me.Combo47.Dropdown
End Sub
Private Sub Form_Current()
If Not Me.NewRecord Then Call SetProductNameByLanguage
End Sub
Private Sub Product_Name_KeyUp(KeyCode As Integer, Shift As Integer)
If Me.Combo47.Column(3) = "TH" Then
Me.[Product Name].RowSource = "SELECT ProductName, [Unit/Thai], ProductNameENG , [Unit/Eng] ,[Code] FROM ProductStandard where ([ProductName] like '*" & Me.[Product Name].Text & "*') or ([ProductNameENG] like '*" & Me.[Product Name].Text & "*') or ([Code] like '*" & Me.[Product Name].Text & "*') order by [ProductName],[ProductNameENG] ;"
Me.[Product Name].Dropdown
Else
Me.[Product Name].RowSource = "SELECT ProductNameENG , [Unit/Eng] ,ProductName, [Unit/Thai],[Code] FROM ProductStandard where ([ProductName] like '*" & Me.[Product Name].Text & "*') or ([ProductNameENG] like '*" & Me.[Product Name].Text & "*')or ([Code] like '*" & Me.[Product Name].Text & "*') order by [ProductName],[ProductNameENG] ;"
Me.[Product Name].Dropdown
End If
End Sub
Private Sub SetProductNameByLanguage()
If Me.Combo47.Column(3) = "TH" Then
Me.[Product Name].RowSource = "SELECT ProductName, [Unit/Thai],ProductNameENG, [Unit/Eng] FROM ProductStandard order by ProductName"
Else
Me.[Product Name].RowSource = "SELECT ProductNameENG, [Unit/Eng],ProductName, [Unit/Thai] FROM ProductStandard order by ProductNameENG"
End If
End Sub
Private Sub Product_Name_AfterUpdate()
Me.[Product Code] = Trim(Nz(Combo47, "") & " " & Nz(Me.[Product Name], ""))
If Me.Combo47.Column(3) = "TH" Then
Me.[Combo65] = Me.[Product Name].Column(1)
Me.[Text85] = Null
Else
Me.[Combo65] = Null
Me.[Text85] = Me.[Product Name].Column(1)
End If
End Sub
Code Form order detail ค่ะ
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.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available], Inventory.[disc] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
SetFormState False
If Not IsNull(Me![Customer ID]) Then
SetDefaultShippingAddress
End If
End Sub
Private Sub Customer_ID_Current()
If Not Me.NewRecord Then
Me.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available], Inventory.[disc] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
End If
End Sub
Private Sub Customer_ID_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Customer_ID.RowSource = "SELECT [ID], [Company], [Address For Ship], [ID] , [MemberName] FROM [Customers Extended] where ([Company] like '*" & Me.Customer_ID.Text & "*') or ([Address For Ship] like '*" & Me.Customer_ID.Text & "*') or ([ID] like '*" & Me.Customer_ID.Text & "*')or ([MemberName] like '*" & Me.Customer_ID.Text & "*') order by [Company], [Address For Ship]"
Me.Customer_ID.Dropdown
End Sub
Private Sub Form_Current()
SetFormState
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
Code SubForm order detail ค่ะ ตอนที่เลือกลูกค้าเสร็จแล้วแสดงสินค้าค่ะ
Option Compare Database
Option Explicit
Private Sub Product_ID_AfterUpdate()
'Initialize price and discount for each product change
If Not IsNull(Me![Product ID]) Then
Me![Quantity] = 0
Me.Quantity.Locked = False
Me![Unit Price] = GetListPrice(Me![Product ID])
Me![Discount] = 0
Me![Status ID] = None_OrderItemStatus
Me.Discount = Nz(Me.Product_ID.Column(3), 0)
'Empty Product records mean user wants to delete line item
Else
eh.TryToRunCommand acCmdDeleteRecord
End If
End Sub
Private Sub Form_Current()
If Nz(Me![Status ID], None_OrderItemStatus) = Invoiced_OrderItemStatus Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If
End Sub
Private Sub Quantity_AfterUpdate()
On Error GoTo ErrorHandler
Dim IT As InventoryTransaction
Dim PurchaseOrderID As Long
Dim SupplierID As Long
IT.ProductID = Nz(Me![Product ID], 0)
IT.Quantity = Me![Quantity]
IT.AllOrNothing = True
IT.InventoryID = Nz(Me![Inventory ID], NewInventoryID)
'Request Hold on specified Inventory
If Inventory.RequestHold(Me![Order ID], IT) Then
Me![Inventory ID] = IT.InventoryID
Me![Status ID] = OnHold_OrderItemStatus
'Insufficient Inventory
ElseIf Me![Status ID] <> None_OrderItemStatus And Me![Status ID] <> NoStock_OrderItemStatus Then
MsgBoxOKOnly InsufficientInventory
Me![Quantity] = Me.Quantity.OldValue
'Attempt to create purchase order for back ordered items
ElseIf MsgBoxYesNo(NoInventoryCreatePO) Then
SupplierID = Inventory.FindProductSupplier(IT.ProductID)
'Create purchase order if we have supplier for this product
If SupplierID > 0 Then
If PurchaseOrders.Generate(SupplierID, IT.ProductID, Me![Quantity], Me![Order ID], PurchaseOrderID) Then
PurchaseOrders.OpenOrder PurchaseOrderID
Me![Status ID] = OnOrder_OrderItemStatus
Me![Purchase Order ID] = PurchaseOrderID
eh.TryToSaveRecord
Else
Me![Status ID] = NoStock_OrderItemStatus
End If
'Could not find a supplier for this product
Else
MsgBoxOKOnly CannotCreatePO_NoSupplier
Me![Status ID] = NoStock_OrderItemStatus
End If
Else
Me![Status ID] = NoStock_OrderItemStatus
End If
Done:
Exit Sub
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("Quantity_AfterUpdate") Then Resume
End Sub
Private Sub Status_Name_DblClick(Cancel As Integer)
Select Case Me![Status ID]
Case NoStock_OrderItemStatus, None_OrderItemStatus
Quantity_AfterUpdate
Case OnOrder_OrderItemStatus
Dim PurchaseOrderID As Long
PurchaseOrderID = Nz(Me![Purchase Order ID], 0)
If PurchaseOrderID > 0 Then
PurchaseOrders.OpenOrder PurchaseOrderID
Me.Requery
End If
Case Invoiced_OrderItemStatus
End Select
End Sub
Code Module Customer Order ค่ะ
Option Compare Database
Option Explicit
Public Enum CustomerOrderStatusEnum
New_CustomerOrder = 0
Invoiced_CustomerOrder = 1
Shipped_CustomerOrder = 2
Closed_CustomerOrder = 3
End Enum
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(Customer_ID As String, OrderID As Long) As Boolean
Dim Result
Result = DLookup("[Language]", "Customers", "[ID]=" & CStr(Customer_ID))
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
Function SetStatus(OrderID As Long, Status As CustomerOrderStatusEnum) As Boolean
Dim rsw As New RecordsetWrapper
If rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
With rsw.Recordset
If Not .EOF Then
.Edit
![Status ID] = Status
SetStatus = rsw.Update
End If
End With
End If
End Function
Function Delete(OrderID As Long) As Boolean
Dim rsw As New RecordsetWrapper
If rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
Delete = rsw.Delete
End If
End Function
Option Compare Database
Private Sub Combo47_AfterUpdate()
Me.[Product Code] = Trim(Nz(Combo47, "") & " " & Nz(Me.[Product Name], ""))
Me.[Product Name] = Null
Me.[Product Code] = Null
Call SetProductNameByLanguage
End Sub
Private Sub Combo47_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Combo47.RowSource = "SELECT [ID], [Company], [Address For Ship],[Language],[Code] FROM [Customers Extended] where ([Company] like '*" & Me.Combo47.Text & "*') or ([Address For Ship] like '*" & Me.Combo47.Text & "*') or ([ID] like '*" & Me.Combo47.Text & "*') order by [Company], [Address For Ship];"
Me.Combo47.Dropdown
End Sub
Private Sub Form_Current()
If Not Me.NewRecord Then Call SetProductNameByLanguage
End Sub
Private Sub Product_Name_KeyUp(KeyCode As Integer, Shift As Integer)
If Me.Combo47.Column(3) = "TH" Then
Me.[Product Name].RowSource = "SELECT ProductName, [Unit/Thai], ProductNameENG , [Unit/Eng] ,[Code] FROM ProductStandard where ([ProductName] like '*" & Me.[Product Name].Text & "*') or ([ProductNameENG] like '*" & Me.[Product Name].Text & "*') or ([Code] like '*" & Me.[Product Name].Text & "*') order by [ProductName],[ProductNameENG] ;"
Me.[Product Name].Dropdown
Else
Me.[Product Name].RowSource = "SELECT ProductNameENG , [Unit/Eng] ,ProductName, [Unit/Thai],[Code] FROM ProductStandard where ([ProductName] like '*" & Me.[Product Name].Text & "*') or ([ProductNameENG] like '*" & Me.[Product Name].Text & "*')or ([Code] like '*" & Me.[Product Name].Text & "*') order by [ProductName],[ProductNameENG] ;"
Me.[Product Name].Dropdown
End If
End Sub
Private Sub SetProductNameByLanguage()
If Me.Combo47.Column(3) = "TH" Then
Me.[Product Name].RowSource = "SELECT ProductName, [Unit/Thai],ProductNameENG, [Unit/Eng] FROM ProductStandard order by ProductName"
Else
Me.[Product Name].RowSource = "SELECT ProductNameENG, [Unit/Eng],ProductName, [Unit/Thai] FROM ProductStandard order by ProductNameENG"
End If
End Sub
Private Sub Product_Name_AfterUpdate()
Me.[Product Code] = Trim(Nz(Combo47, "") & " " & Nz(Me.[Product Name], ""))
If Me.Combo47.Column(3) = "TH" Then
Me.[Combo65] = Me.[Product Name].Column(1)
Me.[Text85] = Null
Else
Me.[Combo65] = Null
Me.[Text85] = Me.[Product Name].Column(1)
End If
End Sub
Code Form order detail ค่ะ
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.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available], Inventory.[disc] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
SetFormState False
If Not IsNull(Me![Customer ID]) Then
SetDefaultShippingAddress
End If
End Sub
Private Sub Customer_ID_Current()
If Not Me.NewRecord Then
Me.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available], Inventory.[disc] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
End If
End Sub
Private Sub Customer_ID_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Customer_ID.RowSource = "SELECT [ID], [Company], [Address For Ship], [ID] , [MemberName] FROM [Customers Extended] where ([Company] like '*" & Me.Customer_ID.Text & "*') or ([Address For Ship] like '*" & Me.Customer_ID.Text & "*') or ([ID] like '*" & Me.Customer_ID.Text & "*')or ([MemberName] like '*" & Me.Customer_ID.Text & "*') order by [Company], [Address For Ship]"
Me.Customer_ID.Dropdown
End Sub
Private Sub Form_Current()
SetFormState
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
Code SubForm order detail ค่ะ ตอนที่เลือกลูกค้าเสร็จแล้วแสดงสินค้าค่ะ
Option Compare Database
Option Explicit
Private Sub Product_ID_AfterUpdate()
'Initialize price and discount for each product change
If Not IsNull(Me![Product ID]) Then
Me![Quantity] = 0
Me.Quantity.Locked = False
Me![Unit Price] = GetListPrice(Me![Product ID])
Me![Discount] = 0
Me![Status ID] = None_OrderItemStatus
Me.Discount = Nz(Me.Product_ID.Column(3), 0)
'Empty Product records mean user wants to delete line item
Else
eh.TryToRunCommand acCmdDeleteRecord
End If
End Sub
Private Sub Form_Current()
If Nz(Me![Status ID], None_OrderItemStatus) = Invoiced_OrderItemStatus Then
Me.AllowEdits = False
Else
Me.AllowEdits = True
End If
End Sub
Private Sub Quantity_AfterUpdate()
On Error GoTo ErrorHandler
Dim IT As InventoryTransaction
Dim PurchaseOrderID As Long
Dim SupplierID As Long
IT.ProductID = Nz(Me![Product ID], 0)
IT.Quantity = Me![Quantity]
IT.AllOrNothing = True
IT.InventoryID = Nz(Me![Inventory ID], NewInventoryID)
'Request Hold on specified Inventory
If Inventory.RequestHold(Me![Order ID], IT) Then
Me![Inventory ID] = IT.InventoryID
Me![Status ID] = OnHold_OrderItemStatus
'Insufficient Inventory
ElseIf Me![Status ID] <> None_OrderItemStatus And Me![Status ID] <> NoStock_OrderItemStatus Then
MsgBoxOKOnly InsufficientInventory
Me![Quantity] = Me.Quantity.OldValue
'Attempt to create purchase order for back ordered items
ElseIf MsgBoxYesNo(NoInventoryCreatePO) Then
SupplierID = Inventory.FindProductSupplier(IT.ProductID)
'Create purchase order if we have supplier for this product
If SupplierID > 0 Then
If PurchaseOrders.Generate(SupplierID, IT.ProductID, Me![Quantity], Me![Order ID], PurchaseOrderID) Then
PurchaseOrders.OpenOrder PurchaseOrderID
Me![Status ID] = OnOrder_OrderItemStatus
Me![Purchase Order ID] = PurchaseOrderID
eh.TryToSaveRecord
Else
Me![Status ID] = NoStock_OrderItemStatus
End If
'Could not find a supplier for this product
Else
MsgBoxOKOnly CannotCreatePO_NoSupplier
Me![Status ID] = NoStock_OrderItemStatus
End If
Else
Me![Status ID] = NoStock_OrderItemStatus
End If
Done:
Exit Sub
ErrorHandler:
' Resume statement will be hit when debugging
If eh.LogError("Quantity_AfterUpdate") Then Resume
End Sub
Private Sub Status_Name_DblClick(Cancel As Integer)
Select Case Me![Status ID]
Case NoStock_OrderItemStatus, None_OrderItemStatus
Quantity_AfterUpdate
Case OnOrder_OrderItemStatus
Dim PurchaseOrderID As Long
PurchaseOrderID = Nz(Me![Purchase Order ID], 0)
If PurchaseOrderID > 0 Then
PurchaseOrders.OpenOrder PurchaseOrderID
Me.Requery
End If
Case Invoiced_OrderItemStatus
End Select
End Sub
Code Module Customer Order ค่ะ
Option Compare Database
Option Explicit
Public Enum CustomerOrderStatusEnum
New_CustomerOrder = 0
Invoiced_CustomerOrder = 1
Shipped_CustomerOrder = 2
Closed_CustomerOrder = 3
End Enum
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(Customer_ID As String, OrderID As Long) As Boolean
Dim Result
Result = DLookup("[Language]", "Customers", "[ID]=" & CStr(Customer_ID))
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
Function SetStatus(OrderID As Long, Status As CustomerOrderStatusEnum) As Boolean
Dim rsw As New RecordsetWrapper
If rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
With rsw.Recordset
If Not .EOF Then
.Edit
![Status ID] = Status
SetStatus = rsw.Update
End If
End With
End If
End Function
Function Delete(OrderID As Long) As Boolean
Dim rsw As New RecordsetWrapper
If rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
Delete = rsw.Delete
End If
End Function
57 @R14670
Private Sub Customer_ID_AfterUpdate()
Me.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available], Inventory.[disc] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
...
...
...
End Sub
ในส่วนสีแดง ให้ตัดเครื่องหมายดอกจันทร์ออกเหลือเป็นแค่ like '" คิดว่าน่าจะใช้ได้นะครับ
ปล. รอมา 2 เดือนแล้ว ค่าปรึกษาผมยังไม่ได้เลย คราวนี้ทบยอดไปแล้วบวกดอกเบี้ย 7% ด้วย
Me.sbfOrderDetails.Form.[Product ID].RowSource = "SELECT Inventory.[Product ID], Inventory.[Product Code], Inventory.[Qty Available], Inventory.[disc] from Inventory where [Product Code] like '*" & Customer_ID & "*'"
...
...
...
End Sub
ในส่วนสีแดง ให้ตัดเครื่องหมายดอกจันทร์ออกเหลือเป็นแค่ like '" คิดว่าน่าจะใช้ได้นะครับ
ปล. รอมา 2 เดือนแล้ว ค่าปรึกษาผมยังไม่ได้เลย คราวนี้ทบยอดไปแล้วบวกดอกเบี้ย 7% ด้วย
58 @R14672
ให้ 10 % เลยค๊าาาาาาา ขอบคุณมากค่ะท่าน :)
59 @R14673
ไม่หายค่ะ มันก็ยังขึ้นเป็น Id 4 , 40 , 41 ทุกตัวที่มี 4 อยู่ดีค่ะ :(
60 @R14674
อีกที เพิ่มช่องว่างหน้าดอกจันทร์ like '" & Customer_ID & " *'"
Time: 0.2694s
Option Compare Database
Private Sub Combo47_AfterUpdate()
Me.[Product Code] = Trim(Nz(Combo47, "") & " " & Nz(Me.[Product Name], ""))
Me.[Product Name] = Null
Me.[Product Code] = Null
Call SetProductNameByLanguage
End Sub
Private Sub Combo47_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Combo47.RowSource = "SELECT [ID], [Company], [Address For Ship],[Language] FROM [Customers Extended] where ([Company] like '*" & Me.Combo47.Text & "*') or ([Address For Ship] like '*" & Me.Combo47.Text & "*') or ([ID] like '*" & Me.Combo47.Text & "*') order by [Company], [Address For Ship];"
Me.Combo47.Dropdown
End Sub
Private Sub Form_Current()
If Not Me.NewRecord Then Call SetProductNameByLanguage
End Sub
Private Sub SetProductNameByLanguage()
If Me.Combo47.Column(3) = "TH" Then
Me.[Product Name].RowSource = "SELECT ProductName, [Unit/Thai] FROM ProductStandard order by ProductName"
Else
Me.[Product Name].RowSource = "SELECT ProductNameENG, [Unit/Eng] FROM ProductStandard order by ProductNameENG"
End If
End Sub
Private Sub Product_Name_AfterUpdate()
Me.[Product Code] = Trim(Nz(Combo47, "") & " " & Nz(Me.[Product Name], ""))
If Me.Combo47.Column(3) = "TH" Then
Me.[Combo65] = Me.[Product Name].Column(1)
Me.[Text85] = Null
Else
Me.[Combo65] = Null
Me.[Text85] = Me.[Product Name].Column(1)
End If
End Sub
ตรงช่อง Product Code ไม่ขึ้นเป็นชื่อ อะค่ะ ขึ้นเป็น Idต่อด้วยหน่วยค่ะ อาจารย์