เพื่อนๆหรือ อ.สุภาพ ช่วยดูให้ด้วยครับ (Findfist)
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 237   2
URL.หัวข้อ / URL
เพื่อนๆหรือ อ.สุภาพ ช่วยดูให้ด้วยครับ (Findfist)

code ต่อไปนี้ ผม ดาวโหลดมาจากตัวอย่างครับ ตั้งใจจะทำ linenumber ให้ subform

'============================================================
' The following function is used by the subfrmLineNumber form
'============================================================

Function GetLineNumber(F As Form, KeyName As String, KeyValue)
Dim RS As Recordset
Dim CountLines

On Error GoTo Err_GetLineNumber

Set RS = F.RecordsetClone

' Find the current record.
Select Case RS.Fields(KeyName).Type
' Find using numeric data type key value?
Case DB_INTEGER, DB_LONG, DB_CURRENCY, DB_SINGLE, _
DB_DOUBLE, DB_BYTE
RS.FindFirst "[" & KeyName & "] = " & KeyValue <=====*******
' Find using date data type key value?
Case DB_DATE
RS.FindFirst "[" & KeyName & "] = #" & KeyValue & "#"
' Find using text data type key value?
Case DB_TEXT
RS.FindFirst "[" & KeyName & "] = '" & KeyValue & "'"
Case Else
MsgBox "ERROR: Invalid key field data type!"
Exit Function
End Select

' Loop backward, counting the lines.
Do Until RS.BOF
CountLines = CountLines + 1
RS.MovePrevious
Loop

Bye_GetLineNumber:
' Return the result.
GetLineNumber = CountLines

Exit Function

Err_GetLineNumber:
CountLines = 0
Resume Bye_GetLineNumber

End Function

ผมมี field ชื่อ id type เป็น autonumber เมื่อสั่ง run โปรแกรม จะขึ้น ERROR "Method or data member not found" ตรงบรรทัด
RS.FindFirst "[" & KeyName & "] = " & KeyValue <=====*******
ไม่ทราบว่าเป็นไร ผมเรียกใช้ function นี้ด้วยคำสั่งนี้ครับ
=GetLineNumber([Form],"id",[id])
ใช้ กับ AccessXp แต่ในตัวอย่างใช้งานได้ครับ ผมเองคิดว่าเป็นตรง argument "id" หรือ [id]
หรือไม่ก็ [Form] ไม่รู้จะส่งค่าให้ function อย่างไร เพื่อนๆช่วยด้วยครับ ขอบคุณล่วงหน้าครับ

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

1 @R02350
ผมเดาว่าน่าจะเิกิดจากบันทัดนี้

Dim RS As Recordset

ให้ลองเปลี่ยนเป็น

Dim RS As Object

ดูเผื่อได้ครับ

2 @R02358
ใช้ได้แล้วครับ ใช้ object เหมือนอาจารย์ว่า ทำไมถึงใช้ recordset ไม่ได้ครับ แต่ตัวอย่างที่ download มา runได้นะครับ ไม่มีปัญหา
ขอบคุณอาจารย์ อีกครั้งครับ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0575s