กระทู้เก่าบอร์ด อ.Yeadram
        
           11,330   16		  
          
					  
		    URL.หัวข้อ / 
		    URL
        
        แปลงข้อมูลตัวเลข (จำนวนเงิน) ให้เป็นตัวอักษรจำนวนเ      
    
      ได้จัดทำเอกสารใบเสร็จรับเงินที่ออกจากโปรแกรม Access 2007
แต่ติดปัญหาเรื่องการแปลงตัวเลขที่เป็นจำนวนเงิน ให้เป็น ตัวอักษรจำนวนเงิน
พอที่จะมีวิธีการทำหรือเปล่าคะ
ขอความช่วยเหลือด้วยคะ
    
  แต่ติดปัญหาเรื่องการแปลงตัวเลขที่เป็นจำนวนเงิน ให้เป็น ตัวอักษรจำนวนเงิน
พอที่จะมีวิธีการทำหรือเปล่าคะ
ขอความช่วยเหลือด้วยคะ
				16 Reply in this Topic. Dispaly 1  pages and you are on page number 1 
				
        
    1 @R10481    
        
  
      ลองค้นหาในบอร์ดดูครับ มีตัวอย่างมากมาย    
    
  
        
    2 @R10498    
        
  
      ได้ค้นเจอโค้ด ตามด้านล่างนี้ ลองใช้แล้วตัวอักษรเรียงตามยอดเงินรวม
ได้ถูกต้องดีมาก แต่ติดปัญหาตามรูปภาพที่แนบมา เพราะไม่รู้จะแก้ไขอย่างไร
Function BahtText(ByVal sNum)
Dim sNumber , sDigit , sDigit10
Dim nLen , sWord , sWord2
Dim sByte , I , J
sNumber = Array("", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า")
sDigit = Array("", "สิบ", "ร้อย", "พัน", "หมื่น", "แสน")
sDigit10 = Array("", "สิบ", "ยี่สิบ", "สามสิบ", "สี่สิบ", "ห้าสิบ", "หกสิบ", "เจ็ดสิบ", "แปดสิบ", "เก้าสิบ")
sNum = Replace(FormatNumber(sNum, 2), ",", "")
nLen = Len(sNum)
If sNum = ".00" Then BahtText = "ศูนย์"
For I = 1 To nLen - 3
J = (15 + nLen - I) Mod 6
sByte = Mid(sNum, I, 1)
If sByte <> "0" Then
If J = 1 Then sWord = sDigit10(sByte) Else sWord = sNumber(sByte) & sDigit(J)
BahtText = BahtText & sWord
End If
If J = 0 And I <> nLen - 3 Then BahtText = BahtText & "ล้าน": BahtText = Replace(BahtText, "หนึ่งล้าน", "เอ็ดล้าน")
Next
If Left(sNum, 1) = "1" Then BahtText = Replace(BahtText, "เอ็ดล้าน", "หนึ่งล้าน")
If Left(sNum, 2) = "11" Then BahtText = Replace(BahtText, "สิบหนึ่งล้าน", "สิบเอ็ดล้าน")
If Len(BahtText) > 0 Then BahtText = BahtText & "บาท"
If nLen > 4 Then BahtText = Replace(BahtText, "หนึ่งบาท", "เอ็ดบาท")
sNum = Right(sNum, 2)
If sNum = "00" Then
BahtText = BahtText & "ถ้วน"
Else
If Left(sNum, 1) <> "0" Then BahtText = BahtText & sDigit10(Left(sNum, 1))
If Right(sNum, 1) <> "0" Then BahtText = BahtText & sNumber(Right(sNum, 1))
BahtText = BahtText & "สตางค์"
If Left(sNum, 1) <> "0" Then BahtText = Replace(BahtText, "หนึ่งสตางค์", "เอ็ดสตางค์")
End If
End Function
 
    
    
  ได้ถูกต้องดีมาก แต่ติดปัญหาตามรูปภาพที่แนบมา เพราะไม่รู้จะแก้ไขอย่างไร
Function BahtText(ByVal sNum)
Dim sNumber , sDigit , sDigit10
Dim nLen , sWord , sWord2
Dim sByte , I , J
sNumber = Array("", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า")
sDigit = Array("", "สิบ", "ร้อย", "พัน", "หมื่น", "แสน")
sDigit10 = Array("", "สิบ", "ยี่สิบ", "สามสิบ", "สี่สิบ", "ห้าสิบ", "หกสิบ", "เจ็ดสิบ", "แปดสิบ", "เก้าสิบ")
sNum = Replace(FormatNumber(sNum, 2), ",", "")
nLen = Len(sNum)
If sNum = ".00" Then BahtText = "ศูนย์"
For I = 1 To nLen - 3
J = (15 + nLen - I) Mod 6
sByte = Mid(sNum, I, 1)
If sByte <> "0" Then
If J = 1 Then sWord = sDigit10(sByte) Else sWord = sNumber(sByte) & sDigit(J)
BahtText = BahtText & sWord
End If
If J = 0 And I <> nLen - 3 Then BahtText = BahtText & "ล้าน": BahtText = Replace(BahtText, "หนึ่งล้าน", "เอ็ดล้าน")
Next
If Left(sNum, 1) = "1" Then BahtText = Replace(BahtText, "เอ็ดล้าน", "หนึ่งล้าน")
If Left(sNum, 2) = "11" Then BahtText = Replace(BahtText, "สิบหนึ่งล้าน", "สิบเอ็ดล้าน")
If Len(BahtText) > 0 Then BahtText = BahtText & "บาท"
If nLen > 4 Then BahtText = Replace(BahtText, "หนึ่งบาท", "เอ็ดบาท")
sNum = Right(sNum, 2)
If sNum = "00" Then
BahtText = BahtText & "ถ้วน"
Else
If Left(sNum, 1) <> "0" Then BahtText = BahtText & sDigit10(Left(sNum, 1))
If Right(sNum, 1) <> "0" Then BahtText = BahtText & sNumber(Right(sNum, 1))
BahtText = BahtText & "สตางค์"
If Left(sNum, 1) <> "0" Then BahtText = Replace(BahtText, "หนึ่งสตางค์", "เอ็ดสตางค์")
End If
End Function
 
    
        
    3 @R10499    
        
  
      ทำไมทำแล้วขึ้น #name?
ที่ TextBox ของ Report
    
    
  ที่ TextBox ของ Report
        
    4 @R10500    
        
  
      ช่วยบอกที่นะคะ ว่าต้องแก้ไขอย่างไร    
    
  
        
    5 @R10502    
        
  
      อาการเหมือนกรณีนี้ ลองแก้ตามดูครับ http://www.thai-access.com/yeadram_view.php?topic_id=1484    
    
  
        
    6 @R10511    
        
  
      tool--> References 
--> Microsoft Excel 11.0 Object Library
ที่เครื่องมีแต่ ---->> Microsoft Excel 12.0 Object Library
ใช้ได้มั้ยคะ และลองทำตามแล้วไม่ได้คะ
    
    
  --> Microsoft Excel 11.0 Object Library
ที่เครื่องมีแต่ ---->> Microsoft Excel 12.0 Object Library
ใช้ได้มั้ยคะ และลองทำตามแล้วไม่ได้คะ
        
    7 @R10512    
        
  
      Library ของ Microsoft Office 2007 จะมีเวอร์ชั่นเป็น 12.0 เอามาใช้ได้ครับ แล้วลองทำตามหัวข้อ Enabling Executable Content in Your Databases ใน http://msdn.microsoft.com/en-us/library/bb421308.aspx    
    
  
        
    8 @R10514    
        
  
      ลองทำตามแล้วไม่ได้ มันยังแสดง
Module Not found
และ Marcro error เหมือนเดิม
จากที่สังเกตุดูเหมือนเราเขียนเรียกใช้ Funtion BahtText ไม่ถูกต้อง
    
    
  Module Not found
และ Marcro error เหมือนเดิม
จากที่สังเกตุดูเหมือนเราเขียนเรียกใช้ Funtion BahtText ไม่ถูกต้อง
        
    9 @R10515    
        
  
      ได้ตั้งค่า Security ให้ไม่ต้องแสดง Message Bar ขึ้นมาอีกเป็นการถาวร
ก็ยังไม่ได้
มันแปลกอยู่จุดหนุ่งคือ บางครั้งได้ บางครั้งก็ไม่ได้ขึ้น #Name หรือไม่ก็ Error
    
  ก็ยังไม่ได้
มันแปลกอยู่จุดหนุ่งคือ บางครั้งได้ บางครั้งก็ไม่ได้ขึ้น #Name หรือไม่ก็ Error
        
    10 @R10516    
        
  
      ใน Control Source ของ textbox ใน report เขียนไว้ =BahtText(xxxxx) ด้วยหรือไม่ ต้องมีเครื่องหมาย เท่ากับ ด้วย    
    
  
        
    11 @R10517    
        
  
      ใน Control Source ของ textbox ใน report เขียนไว้แบบนี้คะ
=BahtText([ผลรวม])
*** ซึ่งใน textbox Report ไม่ได้ฟ้องว่าผิด
ตอนนี้ก็เลยไม่แน่ใจว่าทำผิดที่ตรงไหน อ่ะคะ
    
  =BahtText([ผลรวม])
*** ซึ่งใน textbox Report ไม่ได้ฟ้องว่าผิด
ตอนนี้ก็เลยไม่แน่ใจว่าทำผิดที่ตรงไหน อ่ะคะ
        
    12 @R10521    
        
  
      ไม่ทราบเหมือนกันครับ ใครรู้ช่วยแนะนำที    
    
  
        
    13 @R10533    
        
  
      ตอนนี้ทำได้แล้วคะ โดยการสร้าง Form ใหม่ ก็สามารถใช้งานได้แล้วคะ
ขอบคุณมากเลยนะคะที่ช่วยเหลือ
    
  ขอบคุณมากเลยนะคะที่ช่วยเหลือ
        
    14 @R11721    
        
  
      ทำไมที่หน่วยบาท ถ้าเป็น 19,901.00 บาท ถึงอ่านเป็น "หนึ่งหมื่นเก้าพันเก้าร้อยเอ็ดบาทถ้วน" ล่ะครับ ทำไมไม่เป็น "หนึ่งหมื่นเก้าพันเก้าร้อยหนึ่งบาทถ้วน" ล่ะครับ แต่ถ้าเป็น 19,902 บาท อ่านเป็น "หนึ่งหมื่นเก้าพันเก้าร้อยสองบาท" ถ้วนครับ    
    
  
        
    15 @R11735    
        
  
      เข้าใจว่าอ่านแบบนี้ถูกแล้วครับ
เหมือนกับ 101 อ่านว่า ร้อยเอ็ด ไงครับ
    
  เหมือนกับ 101 อ่านว่า ร้อยเอ็ด ไงครับ
        
    16 @R19172    
        
    
      คุณ  UooTAR   ช่วยมาบอกทีครับว่าจะเอาโค้ดที่คุณพิมพ์ไปไว้ตรงไหนของรายงานครับ สมมุมิว่าผมสร้าง textbos ขึ้นมาแล้ว  ให้เราเอาโค้ดไปไว้ที่ไหนครับ    
    
  
      Time: 0.0611s
    
      
		