You can use...
Private Function DBFQuantity() As Double
' Reference : Microsoft ActiveX Data Ojbects 2.0 Library
' Save the dbf file in the program's directory first
Dim FXPConn As New ADODB.Connection
Dim FXPRs As New ADODB.Recordset
Dim FXPDBSQL As String
Dim DBFileName As String, PathDBFileName As String
DBFileName = "sample.dbf"
PathDBFileName = App.Path
FXPDBSQL = "SELECT * FROM " & DBFileName
FXPConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=" & PathDBFileName & ";" & _
"Exclusive=No"
FXPRs.CursorLocation = adUseClient ' we will use the RecordCount property
FXPRs.Open FXPDBSQL, FXPConn, adOpenDynamic, adLockOptimistic
If FXPRs.EOF Then
DBFQuantity = 0
Else
DBFQuantity = FXPRs.RecordCount
End If
FXPRs.Close
FXPConn.Close
End Function
Or use...
Private Function DBFQuantity() As Double
' Reference : Microsoft Remote Data Object 2.0
Dim FXPConn As New rdoConnection
Dim FXPRs As rdoResultset
Dim FXPDBSQL As String
Dim DBFileName As String, PathDBFileName As String
DBFileName = "sample.dbf"
PathDBFileName = App.Path
FXPConn.Connect = "SourceType=DBF;" & _
"SourceDB=" & PathDBFileName & ";" & _
"Driver={Microsoft Visual FoxPro Driver}"
FXPDBSQL = "SELECT * FROM " & DBFileName
FXPConn.CursorDriver = rdUseOdbc
FXPConn.EstablishConnection "rdDriverNoPrompt"
Set FXPRs = FXPConn.OpenResultset(FXPDBSQL, rdOpenKeyset, rdConcurRowVer)
If FXPRs.EOF Then
DBFQuantity = 0
Else
DBFQuantity = FXPRs.RowCount
End If
FXPRs.Close
FXPConn.Close
End Function
I usually use the second sample because it can open that database that is already opened by another user.
Enter your message below
Sign in or Join us (it's free).