แสดงกระทู้

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tongo

หน้า: [1]
1
ขออนุญาติถามต่อยอดครับ วิธีแบบในคลิปสามารถใช้ NAS เป็นเซิฟเวอร์ได้ไหมครับ

เป็นไปได้แต่ไม่แนะนำครับ
nas หน้าที่หลักจัดการไฟล์
มันไม่ได้ออกแบบมาให้ทำงานในรูปแบบของ server สเปคก็ไม่แรงพอ

ถ้าจะแชร์ไฟล์และใช้ฐานข้อมูล sql ด้วย ใช้เป็น server ไปเลยดีกว่าครับ
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

2
ไฟล์ตัวอย่าง
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

3
อีกวิธีครับ https://www.thai-access.com/index.php?topic=640.0
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

4
Private Sub tro_Click()
On Error GoTo monx 'monx=ชื่อแถวที่จะวิ่งไป
     เงื่อนไขต่างๆ.....

monx:
    Select Case Err
        Case 94
            'เงื่อนไข ที่จะให้ทำ ในที่นี้ให้แสดงข้อความ
            msgbox "Please select month and year"
        Case Else
            MsgBox "Error " & Err.Number, vbCritical
    End Select
End Sub
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

5
กรณีที่ต้องการใส่เงื่อนไขให้คิวรี่ วิธีนึงคือให้บรรทัด Criteria (Access ไทยไม่รู้ใช้คำว่าอะไร, "เงื่อนไข" หรือเปล่า) ของฟิลด์ bill_date และ vihecle_no (จริงๆคำสะกดที่ถูกต้องคือ vehicle นะครับ) ใน Qviheclereport อ้างถึงเท็กซ์บ็อกซ์หรือคอมโบบ็อกซ์บนฟอร์ม frmviheclecomh ที่เราได้เลือกเป็นค่าของเงื่อนไขเอาไว้ สำหรับ vihecle_no นั้นคิดว่าไม่มีปัญหา แต่สำหรับ bill_date เราจะสร้างเท็กซ์บ็อกซ์ 2 ตัวเพิ่มเติมไว้บนเมนฟอร์ม สมมุติชื่อ bill_date_from และ bill_date_to เรากำหนดให้ Visible property ของ 2 ตัวนี้เป็น False เพื่อไม่ให้เห็น จุดประสงค์ของ 2 ตัวนี้เพื่อเก็บวันที่แรกและสุดท้ายของเดือน/ปีที่เลือก เช่น 1/9/2019 และ 30/9/2019 สำหรับเดือน 9 ปี 2019 ที่ทำอย่างนี้เพื่อให้เงื่อนไขของฟิลด์ bill_date ในคิวรี่ สามารถอ้างได้อย่างง่ายๆ ต่อไปก็แล้วแต่จะออกแบบไว้ว่าจะให้ subform แสดงคิวรี่ตามเงื่อนไขที่เลือกเมื่อไหร่ สมมุติว่าเมื่อมีการกดปุ่มชื่อ btnRequery แล้วกัน ดังนั้นใน btnRequery_Click event procedure ก็จะต้องรันโค้ดดังต่อไปนี้

โค๊ด: [Select]
Private Sub btnRequery_Click()
   Me.bill_date_from = DateSerial(Me.combo_year , Me.combo_month , 1)
   Me.bill_date_to = DateSerial(Me.combo_year , Me.combo_month + 1 , 0)
   Me.[ชื่อ sub form control].SourceObject = "frmviheclecomd" ' แต่ถ้าผมเข้าใจผิด ถ้า SourceObject ต้องเป็นชื่อ Qviheclereport ก็แก้ให้ถูกต้องด้วย
   Me.[ชื่อ sub form control].Form.Requery ' บรรทัดนี้อย่าเพิ่งใส่ ให้ทดลองดูก่อน ถ้าไม่ใส่แล้วคิวรี่ไม่เปลี่ยนตามเงื่อนไข ค่อยมาใส่
End Sub

กลับมาที่คิวรี่ เราก็จะใส่คำว่า Forms!frmviheclecomh!vihecle_no สำหรับเป็นเงื่อนไขของฟิลด์ videcle_no  และใส่ between Forms!frmviheclecomh!bill_date_from and Forms!frmviheclecomh!bill_date_to สำหรับฟิลด์ bill_date เท่านี้เองครับ

หมายเหตุ :
1. โค้ดทั้งหมดนี้ยังไม่ได้ลองนะครับ และรันแล้วอาจมีผิดพลาด อาจผิด data type ระหว่าง string และ text
2. โค้ดไม่ได้มีการเขียนป้องกันว่า ถ้าไม่ใส่เดือน/ปี จะแสดงข้อความแจ้งเตือนหรืออะไรยังไง ตรงนี้คุณไปจัดการเองแล้วกัน
3. เมื่อเปิดฟอร์มมา เนื่องจากยังไม่ได้ป้อนเลือกอะไร ดังนั้นค่าที่คิวรี่ใช้เป็นเงื่อนไขก็ยังไม่มี อาจจะ error ได้ ผมคิดว่าเราเว้น SourceObject property ของ sub form ว่างๆไว้ดีกว่าครับ (ซึ่งมันจะถูกเติมในโค้ดข้างบน)

โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

6
monthname(1) จะให้ชื่อเต็มเดือน 1
monthname(1, True) จะให้ชื่อย่อเดือน 1 ครับ

ในกรณีเป็นค่าคงที่ ใส่ค่าไปใน RowSource property เลยจะง่ายกว่า  สมมุติคอมโบบ็อกส์คุณใช้ 2 คอลัมน์ คอลัมน์แรกเป็นเลขเดือน อีกคอลัมน์เป็นชื่อย่อเดือน ก็ใส่เป็น 1;"Jan.";2;"Feb.";3;"Mar."
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

7
ถ้าหมายถึงเมื่อเปิดฟอร์มมา จะให้คอมโบบ็อกซ์แสดงปีหลายๆปี ตย.เช่นแสดง 1 ปีย้อนหลังและปีปัจจุบัน ก็ให้กำหนด RowSourceType property ของคอมโบบ็อกซ์เป็น Value List แล้วใส่โค้ดใน Form Load event procedure เป็น

Private Sub Form_Load()
    Me.ชื่อคอมโบบ็อกซ์.RowSource = Year(Date) & ";" & Year(Date) - 1
End Sub
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

8
ผมขอเสนอวิธีเขียนโค้ดที่รวม 2 เงื่อนไขด้วย AND แบบสั้นๆ

Dim Cond1 As String, Cond2 As String

If Nz(Me.combonamesearch,"") = "" Then Cond1 = " TRUE " Else Cond1 = " ([cus_name] = '" & Me.combonamesearch & "') "

If Nz([acculate],"") = "" Then Cond2 = " TRUE " Else Cond2 = " ([acculate] = " & Me.acculatesearch & ") "

Forms!frmhistoryh!frmhistorylist.Form.RecordSource = "select * from Qsaleh_cusprof where " & Cond1 & " AND " & Cond2
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

9
ลองดูตัวอย่างนี้ครับ ทำงานแยกกันได้ ทำงานด้วยกันได้ ไม่รู้แบบที่ต้องการหรือเปล่าอยากได้ส่วนไหนเพิ่มก็บอกได้ครับ


แบบที่ 1 
checkbox ถ้าติ๊กถูก คือการเลือกเฉพาะที่ถูก และถ้าติ๊กออก คือแสดงข้อมูลทั้งหมด

โค๊ด: [Select]
Sub Search()
Dim StrWhere1, StrWhere2, GroupFilter As String

If Not IsNull(Me.combonamesearch) Then
StrWhere1 = "(((Qsaleh_cusprof.cus_name)=[forms]![frmhistoryh]![combonamesearch])"
End If
If Me.acculatesearch = True Then
StrWhere2 = "(((Qsaleh_cusprof.acculate)=[forms]![frmhistoryh]![acculatesearch])"
End If

GroupFilter = IIf(StrWhere1 = "", "", StrWhere1) & IIf(StrWhere2 = "", "", StrWhere2)
GroupFilter = Replace(GroupFilter, ")(((", ") and ((")

If IsNull(Me.combonamesearch) And Me.acculatesearch = False Then
Forms!frmhistoryh!frmhistorylist.Form.RecordSource = "Select * from Qsaleh_cusprof;"

ElseIf IsNull(Me.combonamesearch) And Me.acculatesearch = True Then
Forms!frmhistoryh!frmhistorylist.Form.RecordSource = "Select * from Qsaleh_cusprof where " & GroupFilter & ");"

ElseIf Not IsNull(Me.combonamesearch) And Me.acculatesearch = True Then
Forms!frmhistoryh!frmhistorylist.Form.RecordSource = "Select * from Qsaleh_cusprof where " & GroupFilter & ");"

ElseIf Not IsNull(Me.combonamesearch) And Me.acculatesearch = False Then
Forms!frmhistoryh!frmhistorylist.Form.RecordSource = "Select * from Qsaleh_cusprof where " & GroupFilter & ");"
End If

If Forms!frmhistoryh!frmhistorylist.Form.Recordset.RecordCount = 0 Then
MsgBox "ไม่พบข้อมูลที่ค้นหา", vbInformation, "สถานะการค้นหา"
End If

End Sub

Private Sub acculatesearch_AfterUpdate()
Call Search
End Sub

Private Sub combonamesearch_AfterUpdate()
Call Search
End Sub


แบบที่ 2
คือเงื่อนไขจะมาจากทั้ง 2 Control เช่นถ้าไม่ติ๊กถูก ข้อมูลที่ติ๊กถูกจะหายไป แบบนี้คือ Fix เงื่อนไขที่ตัว checkbox และ combobox ไว้ตลอด ตัวอย่างโค้ด

โค๊ด: [Select]
Sub Search()
Dim StrWhere1, StrWhere2, GroupFilter As String

If Not IsNull(Me.combonamesearch) Then
StrWhere1 = "(((Qsaleh_cusprof.cus_name)=[forms]![frmhistoryh]![combonamesearch])"
End If
StrWhere2 = "(((Qsaleh_cusprof.acculate)=[forms]![frmhistoryh]![acculatesearch])"

GroupFilter = IIf(StrWhere1 = "", "", StrWhere1) & IIf(StrWhere2 = "", "", StrWhere2)
GroupFilter = Replace(GroupFilter, ")(((", ") and ((")

If IsNull(Me.combonamesearch) And Me.acculatesearch = False Then
Forms!frmhistoryh!frmhistorylist.Form.RecordSource = "Select * from Qsaleh_cusprof;"
Else
Forms!frmhistoryh!frmhistorylist.Form.RecordSource = "Select * from Qsaleh_cusprof where " & GroupFilter & ");"
End If
If Forms!frmhistoryh!frmhistorylist.Form.Recordset.RecordCount = 0 Then
MsgBox "ไม่พบข้อมูล", vbInformation, "การค้นหา"
End If
End Sub
Private Sub acculatesearch_AfterUpdate()
Call Search
End Sub

Private Sub combonamesearch_AfterUpdate()
Call Search
End Sub

ลองดูครับ ผิดตรงไหนแจ้งได้นะคับ
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

10
Error นี้เกิดจาก datatype ของคุณกำหนดเป็น Text ครับ แต่โค้ดที่ผมให้ไปนั้นเป็น Number

เพิ่ม เครื่องหมาย ' อีกนิด Error นี้จะหายไปครับเช่น CusID ของคุณ คือ C01 เป็นสตริง ไม่ใช่ตัวเลข
แก้เป็นแบบนี้
If IsNull(DLookup("deal_price", "tblDeal", "[cus_id]= '" & CusID & "' And [pord_id]= " & [ProD] & "")) Then

Me.Price = DLookup("pord_price", "tblProduct", "product_id= " & ProD)
Else
Me.Price = DLookup("deal_price", "tblDeal", "[cus_id]= '" & CusID & "' And [pord_id]= " & [ProD] & "")
End If


โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

11
มันประมาณนี้ครับ
โค๊ด: [Select]
Dim ProD As String
Dim CusID As String
If Not IsNull(Me.Prod_ID) Then
ProD = Me.Prod_ID
CusID = Forms!frmpos.Form.cus_id
If IsNull(DLookup("deal_price", "tblDeal", "[cus_id]= " & CusID & " And [pord_id]= " & [ProD] & "")) Then
Me.Price = DLookup("pord_price", "tblProduct", "product_id= " & ProD)
Else
Me.Price = DLookup("deal_price", "tblDeal", "[cus_id]= " & CusID & " And [pord_id]= " & [ProD] & "")
End If
End If
ตัวอย่าง คร่าวๆ ครับเผื่อเห็นแนวทาง
โพสต์นี้ได้รับคำขอบคุณจาก: Tongo

หน้า: [1]