Skip navigation

Manage DBF by VBA
For some DBF that no have index table (FPT, TBK, CDX , etc.)
I just do anything by Link it into MDB and manage..

And for DBF that come with index table I can not link it into MDB first,
But we can open it by MS EXCEL and save as to another name.
And now we can link it into MDB and can manage them.
In this case I have writen a function like this..

_______________________________________________________________________________________________________
Function Cust_Prod(tbPATH As String, tbNAME As String)
Dim Ex As Excel.Application
Set Ex = CreateObject(“Excel.Application”)
On Error Resume Next
‘Ex.Visible = True
Ex.Workbooks.Open tbPATH & tbNAME & “.DBF”
Ex.ActiveWorkbook.SaveCopyAs tbPATH & “A” & Right(tbNAME, Len(tbNAME) – 1) & “.DBF”
Ex.ActiveWorkbook.CLOSE
Ex.Application.Quit
Set Ex = Nothing
End Function

_______________________________________________________________________________________________________

However, That way not realy work for us because the another name I’d mean to another file not original DBF
So we can read it only

And then I have found the way, I just connect DBF (come with index tables) by OLEDB
First we must download and register one DLL file like VFPOLE.dll (You can find it for free in internet)
And Just copy this to your new module. I hope every one can call my function. ^_^

Global Conn As New ADODB.Connection
Global Rs As New ADODB.Recordset
Global i As Integer
Global j As Long
Global sql As String

‘_______________________________________________________________________________________________________
Function oConn(ByVal pth As String)
On Error GoTo errExit
If Conn.State 0 Then Conn.Close
Conn.Open (“Provider=VFPOLEDB.1;Data Source=” & pth & “;Mode=ReadWrite|” _
& “Share Deny Read|Share Deny Write;Extended Properties=””;User ID=””;Password=””;” _
& “Mask Password=False;Cache Authentication=False;Encrypt Password=False;” _
& “Collating Sequence=MACHINE;DSN=”””)
Exit Function
errExit:
MsgBox Err.Number & ” : ” & Err.Description
End Function

‘_______________________________________________________________________________________________________
Function cConn()
If Rs.State 0 Then Rs.Close
If Conn.State 0 Then Conn.Close
End Function

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

%d bloggers like this: