End Sub
2 ODBC刷新链表的
Public Function Relink() As Boolean
Dim strCn As String
Dim strSrv As String
Dim strUser As String
Dim strPWD As String
Dim strDataBase As String
Dim Rst_Cprk As Recordset
' '判断通过ADO能否连到服务器
If ConnectWB = False Then Exit Function
' 循环处理此数据库的所有表。
For Each tdf In CurrentDb.TableDefs
' 如果表有一个连接串,那么该表是一个链接表。
If Len(tdf.Connect) > 0 Then
tdf.Connect = strConnect
Err = 0
On Error Resume Next
tdf.RefreshLink ' 重新链接该表。
If Err <> 0 Then
Relink = False
Exit Function
End If
End If
Next tdf
Relink = True
End Function
3 ADO刷新链表的
Private Sub Command2_Click()
最后发现数据的读取速度比用友前台操作的速度还快一些.
{:soso_e100:}作者: Benjamin_luk 时间: 2012-7-30 16:04
这是一个生成传递查询的代码:
Public Function CreatePassSQL(SQLName As String, strSQL As String)
Dim qdfPassThrough As DAO.QueryDef, MyDB As Database
Dim strConnect As String
If IsTableQuery("", SQLName) = True Then 'doesn't exist
CurrentDb.QueryDefs.Delete SQLName
End If
Function IsTableQuery(DbName As String, TName As String) As Integer
Dim Db As Database, Found As Integer, Test As String
Const NAME_NOT_IN_COLLECTION = 3265
' Assume the table or query does not exist.
Found = False
' Trap for any errors.
On Error Resume Next
' If the database name is empty...
If Trim$(DbName) = "" Then
' ...then set Db to the current Db.
Set Db = CurrentDb()
Else
' Otherwise, set Db to the specified open database.
Set Db = DBEngine.Workspaces(0).OpenDatabase(DbName)
' See if an error occurred.
If Err Then
MsgBox "Could not find database to open: " & DbName
IsTableQuery = False
Exit Function
End If
End If
' See if the name is in the Tables collection.
Test = Db.TableDefs(TName).Name
If Err <> NAME_NOT_IN_COLLECTION Then Found = True
' Reset the error variable.
Err = 0
' See if the name is in the Queries collection.
Test = Db.QueryDefs(TName$).Name
If Err <> NAME_NOT_IN_COLLECTION Then Found = True
Db.Close
IsTableQuery = Found
End Function 作者: layaman_999 时间: 2012-7-30 16:28
新建一个库,重建建立ODBC链接表,看是否能连上?如果能连上,那么你原来那个库有问题,如果不能连上,可能是你的ODBC配置有问题作者: yedaoan 时间: 2012-8-1 09:39
谢谢楼上各位的热情回复,上面的这些方法,都试过了,都不行,问题的在关键在,网络一旦断开后,JET引擎就挂了,要重新退出ACCESS再进去,所有基于JET引擎的DAO等都用不了,无论你用什么代码,关键是底层的JET引擎OVER了.
接下的解决方案是ADO了,唉,可怜那好用的ODBC链接表!