field name as argument for function
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 228   1
URL.หัวข้อ / URL
field name as argument for function

ถามไว้ที่ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_2000&Number=156729&page=0&view=collapsed&sb=5&o=7&fpart=1#Post156750 
 
เขาต้องการที่จะเขียนฟังก์ชัน เพื่อให้หาค่าสูงสุดของข้อมูลในฟีลด์ใดๆ โดยเขาใช้การวนลูปข้อมูลแต่ละอัน เพื่อหาค่าสูงสุด 
 
ซึ่งผมดูแล้วจะช้ากว่าการใช้ Max() ใน Select Query ครับ 
 
ผมแนะนำให้เขาใช้ DMAX() ยังจะดีเสียอีก 
 
หรือจะลองทำตามความต้องการของเขาก็ได้ แบบนี้ครับ 
 
Function FindHighestValue(strTable As String, strFld As String) 
Dim dbs As Database, rst As Recordset 
Dim strSQL As String 
Set dbs = CurrentDb 
strSQL = "SELECT Max(" & strFld & ") FROM " & strTable 
Set rst = dbs.OpenRecordset(strSQL) 
If Not rst.EOF Then 
    FindHighestValue = rst(0) 
End If 
rst.Close 
dbs.Close 
Set rst = Nothing 
Set dbs = Nothing 
 
End Function 
 
 
ลองใช้ดู 
 
? FindHighestValue("tblMT","ID") 
 5  
 

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

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