กระทู้เก่าบอร์ด อ.Yeadram
        
           1,699   8		  
          
					  
		    URL.หัวข้อ / 
		    URL
        
        Transaction insert      
    
      ได้ค้นหาข้อมูลการ insert into เพื่อสร้าง transaction table ตาม code ที่อยู่ใน board นี้ แต่ติดปัญหาตรงนี้ จะมี หน้าต่าง ตอบรับของ ms.access ทุกครั้ง ถ้าต้องการให้ insert โดยไม่ต้องถาม ทำได้หรือไม่คะ 
code ที่เขียน
Private Sub save_Click()
DoCmd.RunSQL "insert into transaction(TR_No, Rec_Date)values('" & TR_NO & "','" & Rec_Date & "');"
DoCmd.GoToRecord , , acNewRec
        
End Sub
    
  code ที่เขียน
Private Sub save_Click()
DoCmd.RunSQL "insert into transaction(TR_No, Rec_Date)values('" & TR_NO & "','" & Rec_Date & "');"
DoCmd.GoToRecord , , acNewRec
End Sub
				8 Reply in this Topic. Dispaly 1  pages and you are on page number 1 
				
        
    2 @R12022    
        
  
      ขอบคุณมากค่ะ    
    
  
        
    3 @R12023    
        
  
      ขอถามต่ออีกนิดค่ะ ตาม code นี้ 
Private Sub Personalcode_BeforeUpdate(Cancel As Integer)
If Me.Personalcode < 5 Then
MsgBox "Please re input code", vbOKCancel
End If
    
End Sub
เมื่อเราใส่ personcode ตัวอักษรน้อยกว่า 5 จะแสดง msgbox แล้วจะให้ cursor เด้งกลับไปที่ field personcode อย่างเดิมต้องทำอย่างไรคะ
    
    
  Private Sub Personalcode_BeforeUpdate(Cancel As Integer)
If Me.Personalcode < 5 Then
MsgBox "Please re input code", vbOKCancel
End If
End Sub
เมื่อเราใส่ personcode ตัวอักษรน้อยกว่า 5 จะแสดง msgbox แล้วจะให้ cursor เด้งกลับไปที่ field personcode อย่างเดิมต้องทำอย่างไรคะ
        
    4 @R12024    
        
  
      เพิ่ม Me.Personalcode=Null  และ Me.Personalcode.SetFocus
    
  Private Sub Personalcode_BeforeUpdate(Cancel As Integer) 
    If Me.Personalcode < 5 Then 
         MsgBox "Please re input code", vbOKonly
         Me.Personalcode=Null  
         Me.Personalcode.SetFocus
    End If  
End Sub 
    
        
    5 @R12025    
        
  
      ไม่ได้ค่ะ runtime err 
the macro of function set to the beforeupdate or validation rule property for this field is pervent.....
    
    
  the macro of function set to the beforeupdate or validation rule property for this field is pervent.....
        
    6 @R12027    
        
  
      ลองไปวางที่ Afterupdate ดูครับ    
    
  
        
    7 @R12033    
        
  
      แนะนำหน่อยนะครับ คำสั่งนี้ควรใส่หลังการอัพเดท และการตรวจสอบจำนวนอักขระ ผมว่าน่าใช้คำสั่ง Len() นะครับ จะได้ประมาณนี้ครับ
Private Sub Personalcode_AfterUpdate(Cancel As Integer)
If Len(Me.Personalcode) < 5 Then
MsgBox "Please re input code", vbOKonly
Me.Personalcode=Null
Me.Personalcode.SetFocus
End If
End Sub
    
  Private Sub Personalcode_AfterUpdate(Cancel As Integer)
If Len(Me.Personalcode) < 5 Then
MsgBox "Please re input code", vbOKonly
Me.Personalcode=Null
Me.Personalcode.SetFocus
End If
End Sub
        
    8 @R12041    
        
    
      ขอบคุณสำหรับคำแนะนำค่ะ ตอนนี้ไม่ error แล้วค่ะ แต่ว่ากด enter แล้ว cursor ก็ขยับไปที่ field ถัดไป เลยค่ะ ประมาณว่า คำสั่ง setfocus ไม่ทำงาน 
(จะเกี่ยวหรือป่าวค่ะ ว่าเขียน code นี้ ที่ Textbox เมือ enter แล้วก็กระโดดไป field ถัดไปเลยค่ะ)
    
    
  (จะเกี่ยวหรือป่าวค่ะ ว่าเขียน code นี้ ที่ Textbox เมือ enter แล้วก็กระโดดไป field ถัดไปเลยค่ะ)
      Time: 0.6058s
    
      
		
Private Sub save_Click()
DoCmd.SetWarnings False
DoCmd.RunSQL "insert into transaction(TR_No, Rec_Date)values('" & TR_NO & "','" & Rec_Date & "');"
DoCmd.GoToRecord , , acNewRec
End Sub