แสดงกระทู้

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 ... 30 31 32 [33] 34 35 36 ... 46
577
ห้อง MS Access / : Loop เปลี่ยนสีแถบ Navigation
« เมื่อ: 12 มี.ค. 63 , 11:47:36 »
ทำปุ่มพื้นหลัง ให้เป็นสีที่ต้องการใช่ไหมคับ

โค๊ด: [Select]
Sub Formstyle(frm As Form)
Dim ctl     As Control
    For Each ctl In frm.Controls
        If ctl.ControlType = acNavigationButton And ctl.Tag = "b1" Then
                      ctl.BackColor = 11193702
             End If
    Next ctl
End Sub

แต่ถ้าอยากให้เปิดขึ้นมาแล้ว แสดงสี ถ้า tag = B1 ทั้งแบบที่กด Tab อยู่ และ ที่ยังไม่กดก็เพิ่มเป็น
โค๊ด: [Select]
Sub Formstyle(frm As Form)
Dim ctl     As Control
    For Each ctl In frm.Controls
        If ctl.ControlType = acNavigationButton And ctl.Tag = "b1" Then
                      ctl.BackColor = 11193702
                      ctl.PressedColor = 11193702
             End If
    Next ctl
End Sub

578
ครับผมใช่เลยครับ แต่ผมรบกวนอีกนิดนึงครับ
คือไม่ต้องให้เปิดไฟล์ Excel Stock แต่แค่เอา Path มาใส่ที่ Textbox ก็พอครับผม
รบกวนด้วยครับ
ขอบคุณครับ
เหลือแค่นี้ครับ

Dim fd As FileDialog
Dim filePath As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = False
fd.InitialFileName = "D:\Stock"
If fd.Show = True Then
    If fd.SelectedItems(1) <> vbNullString Then
        filePath = fd.SelectedItems(1)       
        Me.txtFolderPath = filePath
    End If
Else
End If
Set fd = Nothing

579
ผมทำการต่อข้อความ ในฟอร์มที่ออกแบบไว้นะครับ

แต่ยังไม่ได้ทำระบบ ส่งข้อมูลไปที่ Outlook

ให้กรอกข้อมูลแล้วกด นำเข้าข้อมูล ดูครับ

580
ภาพที่ 1


ภาพที่ 2


ตารางแรกชื่อ Note มี
ID_Note, ชื่อผู้บันทึก, วันที่, ID_Event

ตารางสองชื่อ Event มี
ID_Event, ชื่อพนักงาน, ประเภท, จำนวนวัน, เริ่มวันที่, บันทึกเพิ่มเติม

พอจะมีวิธีดึงข้อมูลจากฟอร์ม และ ซัพฟอร์มให้ออกมาได้อย่างภาพที่ 2 ไหมครับ ต้องการให้ข้อมูลเป็น text
ในบอร์ดนี้มีให้อัพโหลดภาพครับ พอท่านอัพภาพจากเว็บนอกมันไม่แสดงครับ

581
ความคิดผมอยากทำ Form 1 หน้าแล้วมี Textbox หรือ ช่องเลือกวัน 2 ช่องให้ใส่วันที่ต้องการเริ่มต้นหากับวันสุดท้ายที่ต้องการหาแล้วให้ Query ออกมาเป็น DataSheet ข้อมูลที่ต้องการ ไม่ทราบว่า Criteria ใน Query สามารถทำได้ไหมครับ???
สามารถทำได้ครับ  แนวทางที่คิดมาถูกต้องแล้ว

ผมสมมุติ ฟิลล์ ชื่อ OpenJobs นะครับ
มี textbox 2 ตัวชื่อ txtStartDate กับ txtEndDate
บน form ชื่อ form1

ที่ฟิลล์  OpenJobs ใส่ Criteria ว่า
Between Forms!Form1!txtStartDate And Forms!form1!txtEndDate

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

582
แบบนี้หรอเปล่าครับ
ใช้ Reference ตัว Microsoft Office 16.0 Object Library  ด้วยนะครับ

โค๊ด: [Select]
Dim fd As FileDialog
Dim filePath As String
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = False
fd.InitialFileName = "D:\Stock"
If fd.Show = True Then
    If fd.SelectedItems(1) <> vbNullString Then
        filePath = fd.SelectedItems(1)
        FollowHyperlink filePath
        Me.txtFolderPath = filePath
    End If
Else
End If
Set fd = Nothing


583
มีฟิลด์ SEQ ชนิด Number Long Integer
ต้องการเขียนโคตให้ Run เลขตั้งแต่ที่กำหนด ไปจนหมดเรคคอด
ต้องเขียนยังงัยครับ ขอบคุณครับ
มี 2 แบบไม่รู้ใช่ที่ต้องการไหมนะครับ

แบบที่1
ผมสมมุติมีฟอร์มแบบ Continuous Forms
มี textbox ระบุเลขที่กำหนดชื่อ txtSeqNum
โดยตารางที่จะดำเนินการชื่อ table1
มีฟิลล์ที่จะ รันตัวเลขชื่อ Seq




Private Sub Command0_Click()
Dim db As Database
Dim rs As DAO.Recordset
   Set db = CurrentDb
   Set rs = db.OpenRecordset("table1")   
 rs.MoveFirst
 Do Until rs.EOF
 If Nz(DMax("seq", "table1"), 0) = 0 Then
         rs.Edit
         rs!Seq = Me.txtSeqNum
         rs.Update
Else
         rs.Edit
         rs!Seq = DMax("seq", "table1") + 1
         rs.Update
End If
         rs.MoveNext
Loop
         Me.Requery
End Sub

แบบที่ 2
ถ้าไม่อยากสร้างฟอร์มขึ้นมาเพิ่ม ใช้การสร้าง ปุ่มขึ้นมา 1 ปุ่มแล้วใส่โค้ดนี้เข้าไปเพื่อทำการแก้ไขตาราง ที่ฟิลล์ Seq
โค๊ด: [Select]
Private Sub Command0_Click()
Dim db As Database
Dim rs As DAO.Recordset
Dim IntSeq As Integer
   Set db = CurrentDb
   Set rs = db.OpenRecordset("table1")
   IntSeq = InputBox("ระบุตัวเลขเริ่มต้น", "ระบบรันSeq")   
 rs.MoveFirst
 Do Until rs.EOF
 If Nz(DMax("seq", "table1"), 0) = 0 Then
         rs.Edit
         rs!Seq = IntSeq
         rs.Update
 Else
         rs.Edit
         rs!Seq = DMax("seq", "table1") + 1
         rs.Update
 End If
         rs.MoveNext
 Loop
    End Sub

584

ใช้ Like มาช่วยก็ได้ครับ เจอประโยคนี้ในข้อความก็เข้าเงื่อนไข เช่น

โค๊ด: [Select]
Private Sub Command2_Click()
If Me.Combo1.Value Like "*กรุงไทย*" Then
DoCmd.OpenForm "frm01"
ElseIf Me.Combo1.Value Like "*ไทยพานิชย์*" Then
DoCmd.OpenForm "frm02"
End If
End Sub

585
ผมมี combobox ที่เลือกธนาคารต่างๆ เมื่อเลือกแล้ว ผมจะคลิกที่ปุ่มนึงแล้ว
ให้มันดูว่า เป็นธนาคารไหน แล้วเปิดฟอร์มที่กำหนดไว้

Text ใน combo ไม่ได้มีชื่อธนาคารอย่างเดียว เช่น
ธนาคารกรุงไทย สาขา......
ธนาคารไทยพานิชย์ สาขา.....

ถามว่าจะเขียนโคตยังงัยครับ

ใช้การตัดข้อความก็ได้ครับ โดยกำหนดให้ ถ้าเจอคำว่า "สาขา" แล้ว ให้ตัดข้อความทางขวาทิ้งทั้งหมด เอาเฉพาะทางซ้าย คือชื่อธนาคารนั้นเอง
เช่น ผมสมมุติ combobox รายชื่อธนาคารและสาขาธนาคาร ชื่อ Combo1
โค๊ด: [Select]
Private Sub Command2_Click()
Dim strBankName As String
strBankName = Me.Combo1
strBankName = Left(strBankName, InStr(strBankName, "สาขา") - 1)
strBankName = Replace(strBankName, " ", "") 'ใช้ Function นี้ป้องกันกรณีมีช่องว่างระหว่างข้อความ
DoCmd.OpenForm strBankName
End Sub

หรือถ้าชื่อ Form ไม่ได้ชื่อธนาคารแต่เป็นชื่ออื่นก็ใช้ If มาเช็คเช่น
โค๊ด: [Select]
Private Sub Command2_Click()
Dim strBankName As String
strBankName = Me.Combo1
strBankName = Left(strBankName, InStr(strBankName, "สาขา") - 1)
strBankName = Replace(strBankName, " ", "") 'ใช้ Function นี้ป้องกันกรณีมีช่องว่างระหว่างข้อความ
If strBankName = "ธนาคารกรุงไทย" Then
DoCmd.OpenForm "Frm01"
ElseIf strBankName = "ธนาคารไทยพานิชย์" Then
DoCmd.OpenForm "Frm02"
End If
End Sub


586
ห้อง MS Access / : ทำไม textbox ขึ้น #Name?
« เมื่อ: 04 มี.ค. 63 , 21:01:04 »
ต้องเอา  function หรือ expression ใน Control Source ของ textbox มาดูครับ ว่ากำหนดไว้แบบไหนถึงได้ขึ้นแบบนั้น
เช่น ชื่อ textbox ชื่ออะไรบ้าง (การตั้งชื่อก็มีผลครับ)

แล้วกำหนดไว้อย่างไร สร้างสูตรคำนวนไว้หรือไม่ ต้องดูหลายๆอย่าง
เพราะบางทีเราสร้างสูตรคำนวนโดยอ้างอิงวันที่ แต่ Format วันที่แต่ละเครื่องไม่เหมือนกันก็จะเกิดอาการแบบนั้นได้
หรือเมื่อบ้ายเครืองอาจจะอ้างอิงผิดตำแหน่ง หรืออ้างอิงช่วงผิด

ปกติเวลาตั้งชื่อ textbox นั้น ถ้าตั้ง = PriceA , PriceB ควรตั้ง ว่า txtPriceA , txtPriceB แบบนี้เพื่อไม่ใช่ชื่อซ้ำซ้อนกันกับชื่อ Field

587
ของผม เชื่อม ODBC driver Link Table ต่างๆ เข้ามากำหนด column ได้ปกติ

588
โดย combobox มัน สามารถกำหนด Column ที่จะผูกค่าไว้เช่น กำหนดให้มี ServiceID และ  ServiceType
โดยกำหนดให้ BoundColumn 1 (ServiceID)
กำหนดให้แสดง 2 คอลัมน์
และกำหนด ความกว้างColumn = 0;5
มันจะแสดงเฉพาะ ServiceType แต่ค่าที่เรากำหนดให้เก็บในตารางคือ ServiceID ซึ่งเป็น Number นั้นเองครับ

ซึ่งการ lookup ในตารางก็มีการทำแบบนี้เหมือนกัน คือการให้แสดง column ServiceType  แต่จริงๆแล้วถ้าไม่ lookup นั้นมันเป็น ServiceID ตามปกติครับ

589
ตัว Control เป็น Unbound หรือ Bound ครับ

อ้างถึง
แบบที่พอจบงานแล้วเคลียคอนโทรลทั้งหมด
เคลียทีเดียวหมด ใช้แบบนี้ดูครับ
ใช้กับ Control ที่ Unbound

โค๊ด: [Select]
Sub ResetForm()   
    On Error GoTo Err_Err
    Dim ctl As Control           
    For Each ctl In Me
        If ctl.ControlType = acComboBox Then  'ถ้าเป็นCombobox ทำให้ว่าง
                ctl = Null       
        End If
        If ctl.ControlType = acTextBox Then   'ถ้าเป็น textbox ทำให้ว่าง
                ctl = Null
        End If
        If ctl.ControlType = acCheckBox Then  'ถ้าเป็น Checkbox ทำให้แสดงเป็น False คือไม่ได้ติ๊กเลือก
                ctl = False
        End If
          Next ctl
Exit_err:
        Exit Sub
Err_Err:
        MsgBox Error$
        MsgBox ("ผิดพลาดตรง Reset Form")
        Resume Exit_err
End Sub

เวลาจะเรียกใช้ ที่ปุ่มเซฟ เมื่อเซฟเสร็จแล้ว
ก็ต่อคำสั่งด้วย
Call ResetForm

อ้างถึง
มีวธีทำให้คิวรีแบบอัปเดททำงานพร้อมกันหมดไหมครับ แบบ ไม่ต้องมากดอัทเดททีล่ะกัน แต่ให้กดทีเดียว ทำงานทุกอันอะครับ
พอจะมีวิธีใหมครับ
สั่งทำงานทีเดียวได้เลยเช่น
DoCmd.SetWarnings False  'ปิดระบบสอบถาม
DoCmd.OpenQuery "Query1"
DoCmd.OpenQuery "Query2"
DoCmd.OpenQuery "Query3"
DoCmd.SetWarnings True  'เมื่อเรียกใช้คิวรี่ทั้ง 3 เสร็จ ก็ให้เปิดระบบสอบถามปกติ

อ้างถึง
แบบที่พอจบงานแล้วเคลียเรคคอททั้งหมด
เคลียเรคคอร์ดทั้งหมด ในตารางใช่หรือไม่ถ้าใช่สามารถใช้คำสั่ง Sql ลบได้เช่น

Dim db As Database
Set db = CurrentDb
db.Execute "DELETE ชื่อตาราง.* FROM ชื่อตาราง;"

อ้างถึง
แบบเลือกให้ลบข้อมูลในเรคคอทที่ต้องการได้

เราสามารถใช้คำสั่งแบบข้างบน โดยกำหนดลบจาก ID เช่น

    Dim strSQL as string
    DoCmd.SetWarnings False
    strSQL = "Delete * From [student] WHERE [Student ID]='007'"
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True

คำสั่งนี้ก็จะลบเรคคอร์ดจากตาราง Student โดยจะลบเรคคอร์ดที่ Student ID = 007 ออกไป

590
ของคุณไม่มีคับ มีแต่ access ของ Office ไม่มี สังเกตุดีๆ ของคุณ 4 ของผม 6
ต้องเพิ่ม Microsoft Office 16 Object Library เข้ามาด้วย
แล้วก็ตัว Runtime

591
ตั้งค่า Reference ครับ


ต้องมี Microsoft Office xx Object Library ด้วยครับ

592
อยากได้ตัวอย่าง
คลิกปุ่มแล้วเปิดหน้าต่างเลือกไฟล์(Textfile)
เมื่อเลือกแล้ว มีปุ่มกดเพื่อนนำเข้าไฟล์นั้นมาในฐานข้อมูล
ขอบคุณครับ
สมมุติ ตารางที่จะนำเข้าจากไฟล์ CSV ชื่อ table1 นะครับ

โค๊ด: [Select]
Private Sub Command0_Click()
Dim File As FileDialog
Dim getfile As String
Set File = Application.FileDialog(msoFileDialogFilePicker)
With File
.Title = "เลือก ไฟล์ที่จะนำเข้า"
        .Filters.Clear
        .Filters.Add "Text Files", "*.csv"
.AllowMultiSelect = False
End With
If File.Show Then
getfile = File.SelectedItems.Item(1)

DoCmd.TransferText TransferType:=acImportDelim, TableName:="table1", FileName:=getfile, HasFieldNames:=True
MsgBox "นำ้้เข้าเรียบร้อยแล้ว"

End If
End Sub


593
ลองดูครับ

โค๊ด: [Select]
Private Sub cmdSave_Click()
Dim ctrl As Control
Dim mSave As Boolean
Dim DontDuplicate As String
Dim str1 As String
str = Empty

'---------------------------------------------------------------------------------------------
' Copy Part 2 = Part 1

        Me.txtNationalID2 = Me.txtNationalID1
        Me.txtNamePrefixThai2 = Me.txtNamePrefixThai1
        Me.txtFirstNameThai2 = Me.txtFirstNameThai1
        Me.txtLastNameThai2 = Me.txtLastNameThai1
        Me.txtNamePrefixEng2 = Me.txtNamePrefixEng1
        Me.txtFirstNameEng2 = Me.txtFirstNameEng1
        Me.txtLastNameEng2 = Me.txtLastNameEng1
        Me.txtNickName2 = Me.txtNickName1
        Me.txtAddessNo2 = Me.txtAddessNo1
        Me.txtVillageNo2 = Me.txtVillageNo1
        Me.txtRoad2 = Me.txtRoad1
        Me.txtSubDistrict2 = Me.txtSubDistrict1
        Me.txtDistrict2 = Me.txtDistrict1
        Me.txtProvince2 = Me.txtProvince1
        Me.txtPostcode2 = Me.txtPostcode1
        Me.txtTelephoneMobile2 = Me.txtTelephoneMobile1
'---------------------------------------------------------------------------------------------
' Check IsNullOrEmpty

For Each ctrl In Me.Controls
    If TypeOf ctrl Is TextBox Then
        If isnullorEmptyTbx(ctrl) Then
            ctrl.BackColor = RGB(119, 192, 212)
            ctrl.BorderColor = RGB(157, 187, 97)
            str = str & ctrl.Tag & vbNewLine
        Else
            ctrl.BackColor = vbWhite
            ctrl.BorderColor = RGB(192, 192, 192)
        End If
    End If
    Next ctrl
   
For Each ctrl In Me.Controls
    If TypeOf ctrl Is ComboBox Then
        If isnullorEmptyCbx(ctrl) Then
            ctrl.BackColor = RGB(119, 192, 212)
            ctrl.BorderColor = RGB(157, 187, 97)
            str = str & ctrl.Tag & vbNewLine
        Else
            ctrl.BackColor = vbWhite
            ctrl.BorderColor = RGB(192, 192, 192)
        End If
    End If
    Next ctrl
   
    If IsNull(str) Or str = "" Then
   
        DontDuplicate = Me.txtNationalID1.Value
        str1 = "[NationalID]=" & "'" & DontDuplicate & "'"
       
        If Me.txtNationalID1 = DLookup("[NationalID]", "tblContractor", str1) Then
        MsgBox "A record " & txtNationalID1 & " is duplicate. " & "Please check record.", vbInformation
        Me.Undo
        Exit Sub
    Else
        '---------------------------------------------------------------------------------------------
' Insert into table

        If MsgBox("Are you sure you want to save?", vbQuestion + vbYesNo, "Save Confirmation") = vbYes Then
            mSave = True
            On Error Resume Next
            DoCmd.SetWarnings False
   
            DoCmd.RunSQL "INSERT INTO tblContractor([NationalID],[NamePrefixThai],[FirstNameThai],[LastNameThai],[NamePrefixEng],[FirstNameEng],[LastNameEng],[NickName],[BirthDate],[BloodGroup],[AddessNo],[VillageNo],[Road],[SubDistrict],[District],[Province],[Postcode],[TelephoneMobile],[ImagePath])" & _
            "Values ('" & Me.txtNationalID1 & "', '" & Me.txtNamePrefixThai1 & "', '" & Me.txtFirstNameThai1 & "', '" & Me.txtLastNameThai1 & "', '" & Me.txtNamePrefixEng1 & "', '" & Me.txtFirstNameEng1 & "', '" & Me.txtLastNameEng1 & "', '" & Me.txtNickName1 & "', '" & Me.txtBirthDate & "', '" & _
            Me.txtBloodGroup & "', '" & Me.txtAddessNo1 & "', '" & Me.txtVillageNo1 & "', '" & Me.txtRoad1 & "', '" & Me.txtSubDistrict1 & "', '" & Me.txtDistrict1 & "', '" & Me.txtProvince1 & "', '" & Me.txtPostcode1 & "', '" & Me.txtTelephoneMobile1 & "', '" & Me.txtImagePath & "');"
   
            DoCmd.RunSQL "INSERT INTO tblWork([NationalID],[NamePrefixThai],[FirstNameThai],[LastNameThai],[NamePrefixEng],[FirstNameEng],[LastNameEng],[NickName],[AddessNo],[VillageNo],[Road],[SubDistrict],[District],[Province],[Postcode],[TelephoneMobile],[CompanyID],[PlantID],[DepartmentID],[SectionID],[SubSectionName],[JobAreaName]," & _
            "[WorkDetail],[ContractType],[WorkContractID],[CompanyHiringDate],[JobAreaEntryDate])" & _
            "Values ('" & Me.txtNationalID2 & "', '" & Me.txtNamePrefixThai2 & "', '" & Me.txtFirstNameThai2 & "', '" & Me.txtLastNameThai2 & "', '" & Me.txtNamePrefixEng2 & "', '" & Me.txtFirstNameEng2 & "', '" & Me.txtLastNameEng2 & "', '" & Me.txtNickName2 & "', '" & Me.txtAddessNo2 & "', '" & _
            Me.txtVillageNo2 & "', '" & Me.txtRoad2 & "', '" & Me.txtSubDistrict2 & "', '" & Me.txtDistrict2 & "', '" & Me.txtProvince2 & "', '" & Me.txtPostcode2 & "', '" & Me.txtTelephoneMobile2 & "', '" & Me.txtCompanyID & "', '" & Me.txtPlantID & "', '" & Me.txtDepartmentID & "', '" & _
            Me.txtSectionID & "', '" & Me.txtSubSectionName & "', '" & Me.txtJobAreaName & "', '" & Me.txtWorkDetail & "', '" & Me.txtContractType & "', '" & Me.txtWorkContractID & "', '" & Me.txtCompanyHiringDate & "', '" & Me.txtJobAreaEntryDate & "');"
           
            MsgBox ("Your record has been successfully saved!")
           
'---------------------------------------------------------------------------------------------
' Clear Textbox

            Me.txtNationalID1 = ""
            Me.txtNamePrefixThai1 = ""
            Me.txtFirstNameThai1 = ""
            Me.txtLastNameThai1 = ""
            Me.txtNickName1 = ""
            Me.txtNamePrefixEng1 = ""
            Me.txtFirstNameEng1 = ""
            Me.txtLastNameEng1 = ""
            Me.txtBirthDate = ""
            Me.txtBloodGroup = ""
            Me.txtAddessNo1 = ""
            Me.txtVillageNo1 = ""
            Me.txtRoad1 = ""
            Me.txtSubDistrict1 = ""
            Me.txtDistrict1 = ""
            Me.txtProvince1 = ""
            Me.txtPostcode1 = ""
            Me.txtTelephoneMobile1 = ""
            Me.txtImagePath = ""
           
            Me.txtNationalID2 = ""
            Me.txtNamePrefixThai2 = ""
            Me.txtFirstNameThai2 = ""
            Me.txtLastNameThai2 = ""
            Me.txtNamePrefixEng2 = ""
            Me.txtFirstNameEng2 = ""
            Me.txtLastNameEng2 = ""
            Me.txtNickName2 = ""
            Me.txtAddessNo2 = ""
            Me.txtVillageNo2 = ""
            Me.txtRoad2 = ""
            Me.txtSubDistrict2 = ""
            Me.txtDistrict2 = ""
            Me.txtProvince2 = ""
            Me.txtPostcode2 = ""
            Me.txtTelephoneMobile2 = ""
            Me.txtCompanyID = ""
            Me.txtPlantID = ""
            Me.txtDepartmentID = ""
            Me.txtSectionID = ""
            Me.txtSubSectionName = ""
            Me.txtJobAreaName = ""
            Me.txtWorkDetail = ""
            Me.txtContractType = ""
            Me.txtWorkContractID = ""
            Me.txtCompanyHiringDate = ""
            Me.txtJobAreaEntryDate = ""
            Me.Requery
        Else
            mSave = False
            Me.Undo           
            Exit Sub
        End If
    End If     
     Else
     MsgBox "Please enter data for all the required fields", vbInformation + vbOKOnly, "Form is not fullfilled completly"
        Exit Sub
           End If
End Sub

594
อ่อข้อมูลเป็น Bound Control อยู่แล้ว งั้นก็ทำแบบนี้ละครับ

หน้า: 1 ... 30 31 32 [33] 34 35 36 ... 46