liên kết dữ liệu nguồn trong access2003

Liên hệ QC

BinhTam

Thành viên thường trực
Tham gia
2/12/06
Bài viết
238
Được thích
30
Chào các bạn,

Trong access2003, mình có dùng chức splitdata wỉzad.

Mình có tạo 1 form: gồm 1 textbox(đường dẫn file data : mặc định d:\db1_be.mdb) và một nút lệnh "link" (dùng thủ công khi thay đổi đường dẫn mới của file data thì mình biết rồi)

Nay mình muốn nhận code để khi mình nhập đường dẫn mới vào hộp textbox và bấm nút lệnh "link" thì sẽ cập nhật theo đường dẫn mới.

Rất mong nhận sự trợ giúp của các bạn.

Thanks,
BìnhTâm
 

File đính kèm

  • link.zip
    74.6 KB · Đọc: 327
Chào các bạn,

mình đã tìm thấy code trong relink table trong website: allapi.net

mình sẽ gửi code cho bạn nào cần.


Chào các bạn,

Trong access2003, mình có dùng chức splitdata wỉzad.

Mình có tạo 1 form: gồm 1 textbox(đường dẫn file data : mặc định d:\db1_be.mdb) và một nút lệnh "link" (dùng thủ công khi thay đổi đường dẫn mới của file data thì mình biết rồi)

Nay mình muốn nhận code để khi mình nhập đường dẫn mới vào hộp textbox và bấm nút lệnh "link" thì sẽ cập nhật theo đường dẫn mới.

Rất mong nhận sự trợ giúp của các bạn.

Thanks,
BìnhTâm
 
module liên kết dữ liệu từ xa

Public Function Dlinks(tentable As String) As Boolean


Dim vAppPath As String, vBackEndPath As String, filedb As String
Dim dbLocal As Database
Dim tdf As TableDef
Dim vCount As Long

On Error GoTo ErrorCode 'trap errors including No Linked Table Found (see below)

'Check if DatabaseName.ini file exists and if not then create a new one
Set dbLocal = CurrentDb()
vAppPath = dbLocal.Name 'fetch filename of front-end file
vAppPath = Left(vAppPath, Len(vAppPath) - 3) 'replace ...mdb (assumes extension is .mdb or .mde)
vAppPath = vAppPath & "ini" 'with ...ini
If Dir(vAppPath) = "" Then 'if .ini file not present on disk then
filedb = Txtpath 'show file selector and choose back-end file
Dlinks = False 'return False if user cancels File Selector dialog
If filedb = "" Then Exit Function 'abort if user cancels File Selector (Dlinks = False)
Open vAppPath For Binary As #1 'create new .ini file (use same filename as front end)
Put #1, , filedb 'write new .ini file to disk with pathname of back end
Close #1 'close file
End If

'Fetch full path and filename of back end file from .ini file
Open vAppPath For Binary As #1 'open .ini file
filedb = String(LOF(1), "*") 'fill filedb with * first
Get #1, , filedb 'read .ini file from disk into filedb
Close #1 'and close file

'Copy pathname and filename of back end file into vBackEndPath (using an existing table)
vBackEndPath = CurrentDb.TableDefs(tentable).Connect 'fetch connection string for specified table
vBackEndPath = Right(vBackEndPath, Len(vBackEndPath) - 10) 'and remove prefix string (;DATABASE=)

'If back end location stored in front end <> back end location from the .ini file then relink tables
If filedb <> vBackEndPath Then 'if back end file location not the same then
DoCmd.Hourglass True
vCount = dbLocal.TableDefs.Count 'fetch No of tables to relink
Call SysCmd(acSysCmdInitMeter, "Relinking Tables to File " & filedb, vCount)
vCount = 0 'set table counter to 0
For Each tdf In dbLocal.TableDefs 'loop through all (non-system) tables
If Len(tdf.Connect) > 0 Then 'skip if system table
vCount = vCount + 1 'inc table counter
tdf.Connect = ";DATABASE=" & filedb 'set pathname + filename of back-end
tdf.RefreshLink 'and make link to back end (if error go to ErrorCode)
End If
Call SysCmd(acSysCmdUpdateMeter, vCount + 1) 'show progress bar
Next tdf 'repeat till all tables linked
DoCmd.Hourglass False
Call SysCmd(acSysCmdRemoveMeter) 'hide progress bar
End If
Dlinks = True 'return with no error (Dlinks = True)
dbLocal.Close 'close local database
Set dbLocal = Nothing
Exit Function 'exit (Dlinks = True)

ErrorCode:
If Err = 3011 Then Resume Next 'if Error 3011 then carry on (see separate Word documentation)
Call SysCmd(acSysCmdRemoveMeter) 'hide progress bar
DoCmd.Hourglass False
MsgBox Err & " " & Err.Description 'show error and then
Dlinks = False 'return False (and quit application) if serious error

End Function

vidu : bạn tạo 1 form với 1 textbox với name : txtpath ( đây là đường dẫn file data.mdb), 1 textbox với name : txttable( đây là tên table bất kỳ mà bạn biết trong file data.mdb), 1 button




Bạn cho mình với nhé. Thanks in advance.
 
Cảm ơn đã thông báo

"Bài không dấu Tiếng Việt sẽ bị xoá, phải đặt tên tựa đề rõ nghĩa và tránh dùng các từ Help me, cứu cứu, cứu em, gấp gấp,..."

Chào các bạn,

Trong access2003, mình có dùng chức splitdata wỉzad.

Mình có tạo 1 form: gồm 1 textbox(đường dẫn file data : mặc định d:\db1_be.mdb) và một nút lệnh "link" (dùng thủ công khi thay đổi đường dẫn mới của file data thì mình biết rồi)

Nay mình muốn nhận code để khi mình nhập đường dẫn mới vào hộp textbox và bấm nút lệnh "link" thì sẽ cập nhật theo đường dẫn mới.

Rất mong nhận sự trợ giúp của các bạn.

Thanks,
BìnhTâm
 
Web KT
Back
Top Bottom