แสดงกระทู้

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 ... 31 32 33 [34] 35 36 37 ... 46
595
ครับ ต้องตั้งค่าตรงนี้เป็นไทย หรือ อังกฤษ ครับ



ตัวอย่างแปลงแล้วด้านล่างครับ

596
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
   
   
'---------------------------------------------------------------------------------------------
'CheckDuplicate
   DontDuplicate = Me.txtNationalID1.Value
           str1 = "[National]=" & "'" & DontDuplicate & "'"
       
        If Me.txtNationalID1 = DLookup("[NationalID]", "tblContractor", str1) Then
        MsgBox "A record " & txtNationalID1 & " is duplicate. " & "Please check record.", vbInformation
       exit sub
   else
' Insert into table
   If IsNull(str) Or str = "" Then
           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
        Else
'            MsgBox "Please enter data for all the required fields below" & vbNewLine & _
'            String(52, "-") & vbCrLf & str, vbInformation + vbOKOnly, "Form is not fullfilled completly"
            MsgBox "Please enter data for all the required fields", vbInformation + vbOKOnly, "Form is not fullfilled completly"
        Exit Sub
       
        End If
End if
End Sub

597
โค๊ด: [Select]
Private Sub Form_BeforeUpdate(Cancel As Integer)
   Dim ctl As Control
   Dim msg As String
   On Error GoTo Err_BeforeUpdate
   If Me.Dirty Then
   msg = (MsgBox("คุณต้องการบันทึกหรือไม่?", vbYesNo + vbQuestion, "Save Record"))
   If msg = vbNo Then
         Me.Undo
    End If
   If msg = vbYes Then
         Modified = Now()
         ModifiedBy = CurrentUser()
      End If
   End If
Exit_BeforeUpdate:
   Exit Sub
Err_BeforeUpdate:
   MsgBox Err.Number & " " & Err.Description
   Resume Exit_BeforeUpdate
End Sub


ยุบรวมกัน เมื่อเราตอบ Yes ครับ
โดย จากโค้ดนี้ ต้องมี textbox  Modified และ ModifiedBy ไว้รับค่าด้วยนะ
         Modified = Now()   คือ Modified จะจัดเก็บวันที่และเวลาตอนนั้นไว้
         ModifiedBy = CurrentUser() คือ ModifiedBy จะจัดเก็บUser ที่ทำการบันทึก

แต่ปกติผมไม่ค่อยใช้ Event BeforeUpdate ครับ
ถ้ามีตัวอย่างผมเพิ่มเติมให้ได้ครับ

598
อ้างถึง
บ้านเลขที่ ให้เป็นตัวเลขและ มี / ได้
Private Sub txtAddress_KeyPress(KeyAscii As Integer)
If (KeyAscii > 46 And KeyAscii < 58)  Then
      KeyAscii = KeyAscii
      Else:
      KeyAscii = 0
   End If
End Sub

อ้างถึง
3. เบอร์ = ตัวเลข ใน tbl เป็น text

สมมุติ txtPhoneNumber

Private Sub txtPhoneNumber_KeyPress(KeyAscii As Integer)
If (KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii = 8) Then
      KeyAscii = KeyAscii
      Else:
      KeyAscii = 0
   End If
End Sub

จะพิมพ์ได้เฉพาะตัวเลขครับ แต่สามารถใช้ Space Bar ได้ เผื่อว่าต้องการพิมพ์เบอร์ 000 0000000  แบบนี้
อ้างถึง
NameEN = เฉพาะอักษรภาษาอังกฤษ

Private Sub txtWordsEng_KeyPress(KeyAscii As Integer)
If (KeyAscii > 65 And KeyAscii < 90) Or (KeyAscii > 97 And KeyAscii < 122) Then
 KeyAscii = KeyAscii
      Else:
      KeyAscii = 0
End If
End Sub
อ้างถึง
ชื่อไทย = เฉพาะอักษรไทย
Private Sub txtWordsTH_KeyPress(KeyAscii As Integer)
If Not (KeyAscii > 0 And KeyAscii < 32) And Not (KeyAscii > 32 And KeyAscii < 127) Then
 KeyAscii = KeyAscii
      Else:
      KeyAscii = 0
End If
End Sub

สำหรับ ใส่ชื่อไทย กำหนดให้ยอมรับการกด Spacebar ได้เพื่อให้เว้นช่องว่างกรณี มีทั้งชื่อและนามสกุล

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

วันนี้ตอนเช้า กำลังจับภาพจะนำแสดงเพิ่ม กำลังคลิกเข้ามาเจอคำตอบที่ต้องการแล้ว ขอบคุณครับผม
ชอบแบบที่ 3 ที่เสนอมาเพิ่ม จริงๆคือถ้าทำได้ตามคำตอบที่ตัวเองต้องการ ก็จะคัดลอกฟอร์มเปลี่ยนชื่อเป็นงานที่ต้องทำประจำทุกคาบ...

ถ้ามีแนวคิดแบบไหน ที่อยากทำแต่ยังทำไม่ได้
ท่านลองอธิบายมาให้ชัดเจนนะครับ เพื่อจะช่วยได้  :miao:

600
ห้อง MS Access / : Record Source
« เมื่อ: 26 ก.พ. 63 , 11:42:02 »
ก่อนอื่นถ้าน้องอยากเริ่มสร้างโปรแกรม สิ่งเริ่มต้นที่ควรศึกษาก่อนคือ
1.ER Diagram

2.ศึกษาความสัมพันธ์ของตาราง (RelationShip)

3.ศึกษาการทำ normalization เพื่อให้ได้ข้อมูลที่ถูกต้องไม่ซ้ำซ้อนกัน

รวม ทุกขั้นตอนจากลิ้งนี้ เครดิตอาจารย์ TTT
https://www.youtube.com/watch?v=HuztS7t9hZc

การสร้างโปรแกรม ต้องกำหนดเป้าหมาย และทำเป็นขั้นตอนครับเช่น
1.กำหนดวัตถุประสงค์ของฐานข้อมูลว่าเราจะสร้างเพื่ออะไร (ศึกษา ER Diagram)
2.ค้นหาและจัดระเบียบข้อมูล ที่คุณอาจต้องการบันทึกไว้ในฐานข้อมูล เช่น ชื่อผลิตภัณฑ์และหมายเลขคำสั่งซื้อ ชนิดข้อมูลเช่น เป็น อักษร วันที่ ตัวเลข อื่นๆ
3.แบ่งข้อมูลเป็นตาราง   
4.เปลี่ยนรายการข้อมูลเป็นคอลัมน์
5.ระบุคีย์หลัก  เลือกคีย์หลักของแต่ละตาราง คีย์หลักเป็นคอลัมน์ที่ใช้ระบุแถวแต่ละแถวแบบไม่ซ้ำกัน ตัวอย่างอาจเป็น ID ผลิตภัณฑ์หรือ ID คำสั่งซื้อ
6.ตั้งค่าความสัมพันธ์ตาราง   (ศึกษาความสัมพันธ์ของตาราง (RelationShip))
7.จำกัดการออกแบบของคุณ  สร้างตารางแล้วเพิ่มระเบียนข้อมูลตัวอย่างบางระเบียน ดูว่าคุณได้รับผลลัพธ์ที่คุณต้องการจากตารางของคุณหรือไม่ ปรับเปลี่ยนการออกแบบตามจำเป็น (การทำ normalization)


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

ซึ่งการกำหนด Gen , Size , offten และ Type นั้น เปรียบเสมือน การแยกส่วนต่างๆ มาเก็บไว้รวมกัน เท่านั้น ไว้เป็นตัวเลือก ในการระบุ รายละเอียดของรถ ในตาราง tbl_Car ครับ

601
ห้อง MS Access / : Record Source
« เมื่อ: 26 ก.พ. 63 , 09:50:10 »
คิวรี่ Car ต้องการสร้างขึ้นเพื่อทำอะไร

ถ้าอยากให้เชื่อมความสัมพันธ์กันเพื่อ แสดง ชื่อ ของแต่ละตารางให้ใส่แบบนี้

SELECT tb_car.no_car, tb_size.size, tb_type.typ, tb_gen.gener
FROM tb_type RIGHT JOIN (tb_size RIGHT JOIN (tb_gen RIGHT JOIN tb_car ON tb_gen.id_gen = tb_car.gen_car) ON tb_size.id_size = tb_car.size_car) ON tb_type.id_type = tb_car.type_car;


ที่คิวรี่ในมุมมอง SQL เอาโค้ดด้านบนไปวาง

602
เป็นฟอร์มหลักแล้วเรียกตาราง tblAssign มาเพื่อทำการแก้ไขข้อมูลโดยตรง ในตารางมีรหัสงานอยู่เป็นจำนวนมาก อยากเช็คเวลาเรียน เพราะเวลาเรียนเช็คทุกวันและทุกคาบ ขี้เกียจเลื่อนเมาส์ไปหารหัสงานตัวนี้  เลยอยากจะให้มันแสดงข้อมูลชื่อฟิล์ด ่jobcode-รหัสงาน jobcode นี้มีค่าเท่ากับ class เวลาเราคลิกเรียกใช้ฟอร์มนี้ อยากให้มันกรองค่าและแสดงเฉพาะ ่jobcode = "class" ครับ
ทำได้หลายแบบมากครับ
แบบที่ 1 ใช้การกำหนด โดยใช้ FormLoad แบบที่คุณอยากทำ


เราใช้การกำหนด RecordSource แบบ Fix เงื่อนไข
ตรงข้อมูลแหล่งระเบียน เว้นว่างๆ ไว้นะครับ แล้วใส่โค้ดนี้เข้าไปแทน

Private Sub Form_Load()
Dim sql As String
sql = "SELECT tblAssign.* FROM tblAssign WHERE (((tblAssign.jobcode)='class'));"
Me.RecordSource = sql
End Sub

แบบที่ 2 กำหนด Criteria ไว้เลยว่าเอาเฉพาะ Class แบบนี้ไม่ต้องใช้ Event Form_Load



แบบที่ 3 ใช้ Combobox ในการเลือก Jobcode ที่ต้องการ อันนี้ผมคิดเผื่อไว้ในอนาคตถ้าอยาก แก้ไขตัวอื่นด้วย

603
ห้อง MS Access / : subform
« เมื่อ: 25 ก.พ. 63 , 17:04:37 »
แบบนี้ครับ
DoCmd.RunCommand acCmdSaveRecord
Forms!frm_Em![qrr_all subform].Form.Requery

604
ห้อง MS Access / : subform
« เมื่อ: 25 ก.พ. 63 , 16:25:21 »
ได้ครับ

605
อธิบายเพิ่มเติมอีกนิดครับ ผมยังงงคำถาม  :XD:

606
Update นิดนึงครับ กรณีไม่มีเศษสตางค์ ให้แสดงแค่บาท ไม่มีสตางค์
โค๊ด: [Select]
Public Function wsiSpellNumber(ByVal MyNumber)
    Dim Bath, Stang, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Million "
    Place(4) = " Billion "
    Place(5) = " Trillion "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert Stang and set MyNumber to dollar amount.
    If DecimalPlace > 0 Then
        Stang = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp = GetHundreds(Right(MyNumber, 3))
        If Temp <> "" Then Bath = Temp & Place(Count) & Bath
        If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Bath
        Case ""
           Bath = ""
        Case "One"
            Bath = "One Bath"
         Case Else
            Bath = Bath & " Bath"
    End Select
    Select Case Stang
        Case ""
            Stang = ""
        Case "One"
            Stang = " and One Stang"
              Case Else
           Stang = " and " & Stang & " Stang"
    End Select
    wsiSpellNumber = Bath & Stang
End Function
     
' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
    Dim result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
    End If
    ' Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        result = result & GetTens(Mid(MyNumber, 2))
    Else
        result = result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = result
End Function
     
' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
    Dim result As String
    result = ""           ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: result = "Ten"
            Case 11: result = "Eleven"
            Case 12: result = "Twelve"
            Case 13: result = "Thirteen"
            Case 14: result = "Fourteen"
            Case 15: result = "Fifteen"
            Case 16: result = "Sixteen"
            Case 17: result = "Seventeen"
            Case 18: result = "Eighteen"
            Case 19: result = "Nineteen"
            Case Else
        End Select
    Else                                 ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: result = "Twenty "
            Case 3: result = "Thirty "
            Case 4: result = "Forty "
            Case 5: result = "Fifty "
            Case 6: result = "Sixty "
            Case 7: result = "Seventy "
            Case 8: result = "Eighty "
            Case 9: result = "Ninety "
            Case Else
        End Select
        result = result & GetDigit _
            (Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = result
End Function
     
' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "One"
        Case 2: GetDigit = "Two"
        Case 3: GetDigit = "Three"
        Case 4: GetDigit = "Four"
        Case 5: GetDigit = "Five"
        Case 6: GetDigit = "Six"
        Case 7: GetDigit = "Seven"
        Case 8: GetDigit = "Eight"
        Case 9: GetDigit = "Nine"
        Case Else: GetDigit = ""
    End Select
End Function


607
ห้อง MS Access / : subform
« เมื่อ: 25 ก.พ. 63 , 15:49:58 »
สั่งให้ subform Requery ครับ

เช่น
ที่ปุ่ม บันทึก(ดูจากมาโคร)

Private Sub Command25_Click()
DoCmd.GoToRecord , , acNewRec
Forms!frm_Em![qrr_all subform].Form.Requery
End Sub

ทีนี้ ปุ่มไหน เมื่อต้องการให้กดแล้ว ให้แสดงค่า Subform ใหม่ก็เอา
Forms!frm_Em![qrr_all subform].Form.Requery
ใส่เข้าไปด้วยครับ

608
เช่น  65.00 อ่านว่า "sixty five bath"  เป็นต้น จนถึงหลักล้าน

สร้าง Module ใส่โค้ดนี้เข้าไป


โค๊ด: [Select]
Public Function wsiSpellNumber(ByVal MyNumber)
    Dim Bath, Stang, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Million "
    Place(4) = " Billion "
    Place(5) = " Trillion "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert Stang and set MyNumber to dollar amount.
    If DecimalPlace > 0 Then
        Stang = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp = GetHundreds(Right(MyNumber, 3))
        If Temp <> "" Then Bath = Temp & Place(Count) & Bath
        If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Bath
        Case ""
           Bath = "No Bath"
        Case "One"
            Bath = "One Bath"
         Case Else
            Bath = Bath & " Bath"
    End Select
    Select Case Stang
        Case ""
            Stang = " and No Stang"
        Case "One"
            Stang = " and One Stang"
              Case Else
           Stang = " and " & Stang & " Stang"
    End Select
    wsiSpellNumber = Bath & Stang
End Function
     
' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
    Dim result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
    End If
    ' Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        result = result & GetTens(Mid(MyNumber, 2))
    Else
        result = result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = result
End Function
     
' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
    Dim result As String
    result = ""           ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: result = "Ten"
            Case 11: result = "Eleven"
            Case 12: result = "Twelve"
            Case 13: result = "Thirteen"
            Case 14: result = "Fourteen"
            Case 15: result = "Fifteen"
            Case 16: result = "Sixteen"
            Case 17: result = "Seventeen"
            Case 18: result = "Eighteen"
            Case 19: result = "Nineteen"
            Case Else
        End Select
    Else                                 ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: result = "Twenty "
            Case 3: result = "Thirty "
            Case 4: result = "Forty "
            Case 5: result = "Fifty "
            Case 6: result = "Sixty "
            Case 7: result = "Seventy "
            Case 8: result = "Eighty "
            Case 9: result = "Ninety "
            Case Else
        End Select
        result = result & GetDigit _
            (Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = result
End Function
     
' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "One"
        Case 2: GetDigit = "Two"
        Case 3: GetDigit = "Three"
        Case 4: GetDigit = "Four"
        Case 5: GetDigit = "Five"
        Case 6: GetDigit = "Six"
        Case 7: GetDigit = "Seven"
        Case 8: GetDigit = "Eight"
        Case 9: GetDigit = "Nine"
        Case Else: GetDigit = ""
    End Select
End Function

เวลาเรียกใช้ก็ใส่ในคิวรี่ ก็ใส่ EngText:wsiSpellNumber([ชื่อฟิลล์]) หรือ ตัวแปรที่จำให้แสดง

Credit : www.microsoftaccessexpert.com

609
ผมสมมุติว่า รายการ เราใส่ในตารางแบบนี้


เราสามารถสร้างปุ่มไว้ก่อนแล้วแสดงรายการจาก combobox หลังจากกดcombobox  ประมาณนี้ครับ เช่น
สมมุติ combobox ชื่อ Combo1 เราอยากแสดงไอดีไหนบ้าง สมมุติอยากให้ แสดงรายการที่ 1 2 3  ก็กำหนด ตรง where clause เอาครับ

Private Sub Command0_Click()
Me.Combo1.SetFocus
Me.Combo1.RowSourceType = "Table/Query"
Me.Combo1.RowSource = "SELECT Table1.ID, Table1.List FROM Table1 WHERE (((Table1.ID)=1 Or (Table1.ID)=2 Or  (Table1.ID)=3));"
Me.Combo1.Dropdown
End Sub

combobox ก็จะแสดง รายการ ที่มีไอดี 1 2 3 คือ แปรงสีฟัน / สบู่ / ยาสระผม เป็นต้น

610
ห้อง MS Access / : ลบค่า Parameter Value ใน Forms ค่ะ
« เมื่อ: 25 ก.พ. 63 , 12:56:54 »
ตัวรายงาน อยากให้มีการ กำหนด Parameter Value ข้อมูลที่ต้องการแสดงในรายงานใช่ไหมครับ

ตัวรายงาน ไม่ต้องใช้ คิวรี่ตัวเดียวกับ Form ก็ได้



วิธีทำ ที่ RecordSource ของรายงาน ลบคิวรี่ออกไปแล้ว กดตรง จุด 3 จุด สังเกตุว่ามันสามารถกำหนด ข้อมูลที่อยากนำมาแสดง เหมือนตอนเราสร้างคิวรี่
เรามากำหนด PARAMETER ตรงนี้ได้เลย (วิธีนี้เราจะไม่ได้สร้างคิวรี่ไว้แต่จะกำหนดในรายงานเลยครับ)

ส่วนตัวคิวรี่ของฟอร์มเอา parameter ออกไปได้เลยครับ

611
คำถามจากมือใหม่ครับ



จากฟอร์มนี้ ต้องกรอกทุกช่อง 
ต้องการทราบวิธีการทำ  ฟอร์มต้องการให้ หากผู้ใช้ไม่กรอกช่องไหน ให้แจ้งเตือนว่าช่องนั้นต้องกรอก  [ อาจจะเป็นดอกจัน ** หรือให้เป็น msgbox ] หรือแต่ละท่านมีแนวทางการทำประมาณไหนแนะนำหน่อยครับ

ใช้ IF ElseIF เลือกเป็นราย textbox เช่น

If IsNull(txtHN) Then
Me.txtHN.setfocus
MsgBox "กรุณาใส่ HN", vbCritical, "โปรแ กรมเวชระเบียน"

ElseIf IsNull(txtID) Then
Me.txtID.setfocus
MsgBox "กรุณาระบุ ID", vbCritical, "โปรแ กรมเวชระเบียน"

ElseIf IsNull(txtPtType) Then
Me.txtPttype.setfocus
MsgBox "กรุณา ระบุ PtType", vbCritical, "โปรแ กรมเวชระเบียน"

ElseIf IsNull(Type_Visit) Then
Me.txtType_Visit.setfocus
MsgBox "กรุณาระบุประเภทการมา รพ.", vbCritical, "โปรแ กรมเวชระเบียน"

ElseIf IsNull(Gender) Then
Me.Gender.setfocus
MsgBox "กรุณาระบุเพศ", vbCritical, "โปรแ กรมเวชระเบียน"

ElseIf IsNull(txtDisc) Then
Me.txtdisc.setfocus
MsgBox "กรุณาระบุเวลาการออกจาก ER", vbCritical, "โปรแ กรมเวชระเบียน"

Else
.........เงื่อนไข ที่จะทำต่อไปถ้ากรอกครบทุกช่องแล้ว

End if

ลองดูครับเป็นแนวทาง

612
ยังไม่ได้ใช่ไหมครับ เดี่ยวผมลองใหม่แปป

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