แสดงกระทู้

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 - PNR

หน้า: 1 ... 39 40 41 [42] 43 44 45 46
739
แก้ไขใหม่ โหลดไปนี้ไปลองดูครับ

โค๊ด: [Select]
Private Sub GroupText_AfterUpdate()
Call RunningID
End Sub

Sub RunningID()
Dim IntID As String
If Not IsNull(Me.GroupText) Then
IntID = Nz(DLookup("Maxgoods_id", "RunID", "LetterID='" & Me.GroupText & "'"), 0)
IntID = IntID + 1
Me.txtgoods_id = Me.GroupText & "-" & Right("0000" & IntID, 4)
Else
MsgBox "กรุณาระบุตัวอักษรกลุ่มให้ครบถ้วน", vbInformation, "ข้อผิดพลาด"
End If

End Sub

ตัวอย่างแก้ไขใหม่คับ

740
คือ คุณต้องการ รวมยอด การรับเข้า การส่งออก จำนวนคงเหลือ เศษรับเข้า เศษจ่ายออก โดยเงื่อนไข ให้รวมถ้า Inhouse_number และ Gcas เหมือนกันหรือเปล่าครับ

เช่นข้อมูลในตารางเป็นแบบนี้
Inhouse_number  / Gcas /   รับเข้า    /  ส่งออก 
11111111111      /  AA  /      10     /   5
11111111111      /  AA  /        5      /   5

คิวรี่ Q_Balance ต้องให้ได้
Inhouse_number  / Gcas /   รับเข้า    /  ส่งออก 
11111111111      /  AA   /      15     /   10

อยากให้แสดงแบบนี้หรือเปล่า ผมไม่ค่อยเข้าใจคำถามเหมือนกันครับ

741
เพิ่มเป็น

Private Sub detail_goods_DblClick(Cancel As Integer)
Me.other_detail.Visible = True
Me.other_detail.SetFocus
Me.detail_goods.Visible = False

End Sub

Private Sub Form_Load()
Me.other_detail.Visible = False
Me.detail_goods.Visible = True
End Sub

Private Sub other_detail_Exit(Cancel As Integer)
Me.detail_goods.Visible = True
Me.detail_goods.SetFocus
Me.other_detail.Visible = False
End Sub

เวลาเรา Enter มันจะกลับไปที่ textbox detail_goods

742
ขอดูโค้ดตอนนี้หน่อยครับ

ความต้องการต่อไปคือ เมื่อใส่ข้อมูลใน Otherdetail แล้ว พอกด Enter ให้ แสดง detail_goods เหมือนเดิมใช่หรือไม่

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


แบบที่ 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

ลองดูครับ ผิดตรงไหนแจ้งได้นะคับ

744
คือเราใส่ข้อมูลบนฟรอมโดยทำเป็น combobox พอกดปุ่มบันทึก อยากให้แสดง ชื่อ
ที่เราทำได้มันแสดง รหัสประชาชน

เช่น tablename
   มี รหัสประชาชน   ชื่อ
        001           ABC

อยากให้ Msgbox แสดง ชื่อ
มี Combobox ชื่อ ComboboxName ผูกกับคอลัมน์หนึ่งไว้เพื่อจัดเก็บในตาราง คือรหัสประจำตัวประชาชน

กำหนด Msgbox แบบนี้ครับ

Msgbox Me.ComboboxName.Column(1)

745
อีกนิดครับ เดิม field other_detail จะอยู่หลัง field detail_goods แและ visible=no  เมื่อ  dbl click ที่field detail_goods ให้ other_detail อยู่หน้าแทน และ visible=yes  ส่วน field detail_goods ไปหลบแทน other_detail  สลับสลับมาครับ(ที่ table ผมมี field ลองรับ 2 data ครับ)

สลับตัว Control ด้วยใช่ไหมคับ เดี่ยวลองดูก่อน

746
ลองดูตัวอย่างนี้คับ

747
กรณีนี้ ถ้าผมสร้าง text field(other_detail) วางทับซ้อน ฟิลด์รายการสินค้า(detail_goods) และ visible=no ไว้  เมื่อเราจะใช้ text fieldนี้ เราก็จะ double click, text field ก็จะ visible และให้ field รายการสินค้า visible=no ผมจะเขียน codeได้้แบบไหนครับ อจ.

field            รายการสินค้า        text field(ที่ซ่อนไว้)
name        detail_goods           other_detail

ใช้ ColumnHidden ก็ได้ครับ

ถ้าบนฟอร์ม

โค๊ด: [Select]
Private Sub detail_goods_DblClick(Cancel As Integer)
Me.other_detail.ColumnHidden = False
Me.other_detail.SetFocus
Me.detail_goods.ColumnHidden = true
End Sub

Private Sub Form_Load()
Me.detail_goods.ColumnHidden = False
Me.other_detail.ColumnHidden = True
End Sub


ถ้าทำบนรายงาน

โค๊ด: [Select]
Private Sub detail_goods_DblClick(Cancel As Integer)
Me.other_detail.Visible = True
Me.other_detail.SetFocus
Me.detail_goods.Visible = False
End Sub

Private Sub Report_Load()
Me.detail_goods.Visible = True
Me.other_detail.Visible = False
End Sub

748
อ้างถึง
เลยใช้คำสั่ง
ให้ไป Setfocus ที่ปุ่ม แล้ว Sendkey {Enter} มันใช้ได้ดีเลยครับ ติดที่มันสั่ง
 Numlock

ใช้ Event  Enter ของปุ่มช่วยก็ได้ครับเช่น
สมมุติปุ่มชื่อ ShowMap
Private Sub ShowMap_Enter()
คำสั่งแสดงแผนที หรือคำสั่งที่ต้องการ
End Sub

ที่ปุ่มที่ต้องการกดก็สั่ง

Private Sub Command1_Click()
Call ShowMap_Enter
End Sub

ถ้าจะทำเงื่อนไขต่อไปเลยแบบไม่ต้องกดปุ่มอื่นๆ ก็ใช้
Call ShowMap_Enter
ได้เลยซึ่งเป็นการประยุกต์ใช้คำสั่งแทนการกด Enter เองได้เลย แบบนี้ทำให้ SendKey ไม่ต้องใช้อีก และไม่ต้องสั่ง setfocus ด้วย
หรือถ้าท่านสั่ง Setfocus ปุ่มShowMap      Event Enter ก็จะทำงานทันทีเช่นกันคับ โดยไม่ต้อง Call อีก

749
เพิ่มเติมต่อจากอาจารย์อีกหน่อยนะครับ

สมมุติตารางชื่อ Table1
Field ชื่อ  CusID,CusName,DocNumber,DocAddDate
Textbox ชื่อ txtFindCusID / txtFindCusName /  txtFindDocNum / txtFindDocAddDate
Form ในการค้นหา ชื่อ frmSearchCustomer
โค๊ด: [Select]
Private Sub Command40_Click()
Dim StrFilter1, StrFilter2, StrFilter3, StrFilter4 As String
Dim GroupFilter As String

'กำหนดเงื่อนไขให้กับตัวแปรว่าถ้ามีข้อมูลจะนำ Where Clause นี้มาต่อประโยคใน Sql
If Not IsNull(Me.txtFindCusID) Then
StrFilter1 = "(((Table1.CusID)=[forms]![frmSearchCustomer]![txtFindCusID])"
End If
If Not IsNull(Me.txtFindCusName) Then
StrFilter2 = "(((Table1.CusName)=[forms]![frmSearchCustomer]![txtFindCusName])"
End If
If Not IsNull(Me.txtFindDocNum) Then
StrFilter3 = "(((Table1.DocNumber)=[forms]![frmSearchCustomer]![txtFindDocNum])"
End If
If Not IsNull(Me.txtFindDocAddDate) Then
StrFilter4 = "(((Table1.DocAddDate)=[forms]![frmSearchCustomer]![txtFindDocAddDate])"
End If

'นำเงื่อนไขที่ได้จากด้านบน มาต่อประโยคกัน
GroupFilter = IIf(StrFilter1 = "", "", StrFilter1) & IIf(StrFilter2 = "", "", StrFilter2) & IIf(StrFilter3 = "", "", StrFilter3) & IIf(StrFilter4 = "", "", StrFilter4)

'ใช้ Replace เพื่อใช้ And ต่อเงื่อนไขใน Where Clause
GroupFilter = Replace(GroupFilter, ")(((", ") and ((")

'นำประโยคที่ได้มากำหนด RecordSource
If IsNull(Me.txtFindCusID) And IsNull(Me.txtFindCusName) And IsNull(Me.txtFindDocAddDate) And IsNull(Me.txtFindDocNum) Then
Me.RecordSource = "Select * from table1;"
Else
Me.RecordSource = "Select * from table1 where " & GroupFilter & ");"
End If
End Sub

ข้อดีคือ  สามารถเลือกค้นหาข้อมูลได้ทุก textbox ที่อยากค้นและ เราใช้การสร้าง RecordSource แค่อันเดียว เพราะ Sql ที่ได้มาจากการสร้างเงื่อนไขค้นหาด้านบนไว้หมดแล้ว

750
ใช้ BeforeUpdate เช็คก็ได้คับ

ที่ปุ่มบันทึกใส่
โค๊ด: [Select]
Private Sub CmdSave_Click()
DoCmd.RunCommand acCmdSaveRecord
End Sub

โค๊ด: [Select]
Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("คุณต้องการบันทึกข้อมูลหรือไม่?", vbQuestion + vbYesNo, "Save Confirmation!!") = vbYes Then
MsgBox ("บันทึกข้อมูลเรียบร้อย!")
Else
Cancel = True
Me.Undo
End If
End Sub

751
ผมลองดูตารางจากไฟล์ตัวอย่างเก่าที่คุณเคยส่งมา ลองไปแก้ตามนี้ดูก่อนครับ
Backup ต้นฉบับไว้ด้วยนะ
1.ลองล้างการจัดรูปแบบ
2.ลองกำหนด Format ของข้อมูลฟิลล์นั้น ตามภาพเพราะอาจจะเกิดจากการกำหนด Format ที่ไม่สอดคล้องกับ access เลยเกิดปัญหานี้ได้


เป็นที่ฟิลล์ไหนลองทำดูครับว่าหายไหม

752
ห้อง MS Access / : รายงาน ยอดรวม Subform Error
« เมื่อ: 25 ก.ย. 62 , 11:51:26 »
แปลงค่า แล้วอ้างอิงตัว Control ดูครับ โดยการอ้างอิงต้องใช้ Reports![ชื่อรายงาน].[ชื่อSub]![ชื่อคอนโทรล] ครับ เช่น
แบบจำนวนเต็ม
=CInt([Reports]![re_Main].[re_sub1]![Text15])

หรือ
แบบทศนิยม
=CDbl([Reports]![re_Main].[re_sub1]![Text15])

753
ลองดูตัวอย่างนี้ครับ พอดีค้นหาเจอจากเว็บนอก และเพิ่มเติมบางส่วนเช่นเลือกข้อมูลจากตารางพิกัส gps ลูกค้าให้ด้วยคับ
ตัวแผนที่อัพเดทล่าสุด 2019
Credit : Philben





754
ตาราง productID ควรตั้งชื่อว่า tblProducts ดีกว่าครับ
ขอดูข้อมูลในตาราง product หน่อย

755



ผมได้ลองสร้างระบบ ตอกบัตรของพนักงานในการเข้างาน มาให้ดูเป็นแนวทางคับ
1.ก่อนใช้งานให้ ใส่ รหัส Barcode ของพนักงานแต่ละคน ในตาราง tblEmployee ก่อนนะครับ ผมใส่ไว้ให้ 2 ไอดีคือ 01 และ 02
2.เมื่อเราแสกน Barcode โปรแกรมจะทำการ Enter อัตโนมัติ
3.ระบบจะบันทึกข้อมูลเข้าสู่ตารางทันทีถ้า Barcode นั้นมีอยู่จริง ถ้าไม่มีอยู่จะมีการแจ้งเตือนให้ครับ
4.รายละเอียดชื่อพนักงานและเวลาในการตอกบัตรนั้นจะแสดงขึ้นมาเมื่อแสกน Barcode ครับ และจะหายไปเองเมื่อครบ 5 วินาที
5.ผมได้สร้างนาฬิกา และ แสดงวันที่ เรียลไทม์ ไว้บนฟอร์มด้วย
6.โดยปกติ พนักงานอาจจะเผลอไปแสกน วันนึงหลายๆ ครั้ง แต่ผมได้สร้างคิวรี่ตรวจเช็คเวลาที่แสกนอันแรกสุดของวันมาแสดงให้ครับ
7.มีระบบสถานะแสดงไว้ให้ด้วยกรณีที่ผิดพลาดก็จะมีข้อความแสดงแจ้งเตือนใหักับพนักงานได้ทราบครับ

ลองดูนะครับ ไม่รู้ได้หรือเปล่า

756
อ้างถึง
กรอกแค่รหัส ที่ textid แล้วให้บันทึก จะใช้ตัวยิงบารโค้ดด้วยคะ

ระบบที่คุณจะทำคือสร้างระบบ แสกนตอกบัตร เวลาเข้าทำงาน และ เวลาออกงาน ของพนักงานหรือเปล่าครับ

เครื่องบาร์โค้ด ปกติจะมีระบบ Enter อัตโนมัติ อยู่แล้ว งั้นเดี่ยวผมลองทำตัวอย่างให้นะครับ

หน้า: 1 ... 39 40 41 [42] 43 44 45 46