รวมฟิวส์ Text

เริ่มโดย naekkhung, 31 ส.ค 20 , 14:05:21

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

naekkhung


จากรูปจะมี text 4 ตัว
1.Description
2.เบอร์โทร
3.รายงานการติดตาม
4.Total คือเอา 1-3 มารวมกัน
คำถามคือตอนนี้ text รายงานการติดตาม เวลาพิมม์ข้อมูลลงไป ผมอยากให้มัน Update ที่ช่อง Total ทันที ตอนนี้ผมใช้เงื่อนไข After Update อยุ่คือว่ามันต้องคีย์ข้อมูลเสร็จแล้วถึงจะ Update ต้องเขียนแบบไหนครับ


  •  

UnKnown

เท่าที่ทราบคือไม่ว่าจะใช้เงื่อนไขไหนก็ต้องพิมพ์เสร็จหรือ Enter ก่อนข้อมูลที่อื่นถึงจะอัพเดทครับ / จะให้เป็นแนวว่าระหว่างพิมพ์ช่องหนึ่งอยู่แล้วให้อีกช่องอัพเดทแบบ Realtime ทันทีเลยทั้งที่ยังไม่ตกลงคงจะไม่มีนะครับ
:ninja:     ลองคิด,ลองทำแนวคนไม่เก่งแอคเซส
หมายเหตุ เพื่อความปลอดภัยโปรดสำรองข้อมูลใว้ก่อนการแก้ไข
  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: naekkhung

naekkhung

ขอบคุณครับมากครับ
  •  

PNR

#3
เราสามารถที่จะพอทำได้ครับ โดยใช้การกำหนด ประกาศตัวแปรเป็น Public นะครับ
ผมสมมุติ text1 ถึง text3 และ textbox แสดงชื่อ total
เพราะโดยปกติ .Text จะใช้ได้กับ คอนโทรลที่ โฟกัสอยู่เท่านั้น
เราจึงควรสร้างตัวแปรขึ้นมาเก็บค่าไว้ก่อนเพื่อนำไปต่อกับ ตัวแปรต่อๆไป ครับ

ดังตัวอย่างโค้ดนี้

Option Compare Database
Public strText1, strText2, strText3 As Variant

Private Sub Form_Current()
Me.total = strText1 & " " & strText2 & " " & strText3
End Sub

Private Sub Text1_Change()
If Len(Me.Text1.Text) > 0 Then
strText1 = Me.Text1.Text
End If
Me.total = strText1 & " " & strText2 & " " & strText3
End Sub
Private Sub Text2_Change()
If Len(Me.Text2.Text) > 0 Then
strText2 = Me.Text2.Text
End If
Me.total = strText1 & " " & strText2 & " " & strText3
End Sub
Private Sub Text3_Change()
If Len(Me.Text3.Text) > 0 Then
strText3 = Me.Text3.Text
End If
Me.total = strText1 & " " & strText2 & " " & strText3
End Sub
Time to stop for me  :dizzy:
  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: naekkhung, UnKnown

PNR

แก้ไขเพิ่มเติมโค้ดนิดนึงกรณีลบข้อมูลออกหมด

Option Compare Database
Public strText1, strText2, strText3 As Variant

Private Sub Text1_Change()
If Len(Me.Text1.Text) > 0 Then
strText1 = Me.Text1.Text
Else
strText1 = Null
End If
Me.total = strText1 & " " & strText2 & " " & strText3
End Sub
Private Sub Text2_Change()
If Len(Me.Text2.Text) > 0 Then
strText2 = Me.Text2.Text
Else
strText2 = Null
End If
Me.total = strText1 & " " & strText2 & " " & strText3
End Sub
Private Sub Text3_Change()
If Len(Me.Text3.Text) > 0 Then
strText3 = Me.Text3.Text
Else
strText3 = Null
End If
Me.total = strText1 & " " & strText2 & " " & strText3
End Sub
Time to stop for me  :dizzy:
  •  

naekkhung

#5
ขอบคุณมากๆเลยครับ แต่ตอนนี้ถ้าเกิด text1 เราไม่ต้องการกรอกข้อมูล แต่ตอนรวม มันจะมีค่าเว้นวรรคมาด้วย ถ้าเราไม่ต้องการทำยังไงครับ
  •  

PNR

#6
อ้างถึงจาก: naekkhung ใน 02 ก.ย 20 , 08:53:40
ขอบคุณมากๆเลยครับ แต่ตอนนี้ถ้าเกิด text1 เราไม่ต้องการกรอกข้อมูล แต่ตอนรวม มันจะมีค่าเว้นวรรคมาด้วย ถ้าเราไม่ต้องการทำยังไงครับ
ใช้ Trim เข้ามาช่วยครับ


Option Compare Database
Public strText1, strText2, strText3 As Variant

Private Sub Text1_Change()
If Len(Me.Text1.Text) > 0 Then
strText1 = Me.Text1.Text
Else
strText1 = Null
End If
OutPutString
End Sub

Private Sub Text2_Change()
If Len(Me.Text2.Text) > 0 Then
strText2 = Me.Text2.Text
Else
strText2 = Null
End If
OutPutString
End Sub

Private Sub Text3_Change()
If Len(Me.Text3.Text) > 0 Then
strText3 = Me.Text3.Text
Else
strText3 = Null
End If
OutPutString
End Sub

Private Sub OutPutString()
Me.total = Trim(strText1 & IIf(IsNull(strText2), Null, " " & strText2) & IIf(IsNull(strText3), Null, " " & strText3))
End Sub
Time to stop for me  :dizzy:
  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: sjs, naekkhung