Query descriptions created in code
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 213   1
URL.หัวข้อ / URL
Query descriptions created in code

มีคนถามไว้ที่ 
http://www.access-programmers.co.uk/forums/showthread.php?s=&postid=107987#post107987 
 
I used the below to try & create a temporary query that will be routinely created  
& deleted whenever it is called. The below code is meant to create it & append  
a description to the query in case sometime in the future I forget what it’s  
purpose is. Problem is that I get an invalid use of property message on the  
fourth line. I’d appreciate any advice.   
 
Set db = CurrentDb  
Set qd = db.CreateQueryDef("qryEnterPayDetails", strSQL)  
db.QueryDefs("qryEnterPayDetails").Properties ("Test desc")  
DoCmd.OpenQuery "qryEnterPayDetails" 
 
__________________ 
thanks, 
Arage 
 
ต้องการสร้าง Description ให้ Query ด้วยโค้ดจะทำได้อย่างไร เพราะต้องการที่จะใส่ข้อความอธิบายการทำงานของ Query แต่ละอัน เพื่อจะได้ค้นหาภายหลังได้ง่ายๆ 
 
ผมแนะนำเขาไปดังนี้ 
 
Function CreateQueryDescrpt(strQuery As String, strDescrpt As String) 
Dim dbs As Database 
Dim qdf As QueryDef 
Dim prop As Property 
 
On Error GoTo Err_CreateQueryDescrpt 
 
Set dbs = CurrentDb 
 
Set qdf = dbs.QueryDefs(strQuery) 
 
With qdf 
    For Each prop In .Properties 
    ' On Error Resume Next 
    ' Check if Description property already set, change it and exit 
        If prop.Name = "Description" Then 
            .Properties("Description") = strDescrpt 
            Debug.Print "Already set" 
            Exit Function 
        End If 
    Next prop 
     
    ' If is not yet there, assign it 
    Set prop = .CreateProperty("Description", dbText, strDescrpt) 
    .Properties.Append prop 
    .Properties.Refresh 
   Debug.Print "Newly set" 
    
End With 
 
Bye_CreateQueryDescrpt: 
    Exit Function 
 
Err_CreateQueryDescrpt: 
    Beep 
    MsgBox Error$, 48 
    Resume Bye_CreateQueryDescrpt 
 
End Function 
 
ซึ่งโค้ดข้างต้นลองปรับไปใช้กับตาราง หรือ object อื่นๆ ของ Access ได้ครับ *** Edited by Supap Chaiya *** 3/9/2546 21:50:30

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06519
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0453s