P
paul.schrum
Access 2003
I am linking tables at startup, and I need to block the linking of
tables which have already been linked.
I accomplish the link with lines like this:
DoCmd.TransferDatabase acLink, "Microsoft Access", _
dbName, acTable, "tbl_tasks", "tbl_tasks"
In which dbName is something like "C:\db\tasks.mdb"
In order to prevent the linking of a table which has already been
linked, I want to wrap the above command in an if-block like so:
if doesTableExist("tbl_tasks") = False then
DoCmd.TransferDatabase acLink, "Microsoft Access", _
dbName, acTable, "tbl_tasks", "tbl_tasks"
end if
I am attempting to implement the Function doesTableExist now, but my
approach, it turns out, is unacceptably slow. I need advice on the
best, fastest way to block Access from linking a given table if the
tablename already exists.
Here is the code for doesTableExist
Function doesTableExist(tableName As String) As Boolean
Dim i, count As Integer
i = 0
count = CurrentDb.TableDefs.count
Dim checkName As String
doesTableExist = False
For i = 0 To count
checkName = CurrentDb.TableDefs(i).Name ' 7 seconds per
execution
If 0 = StrComp(tableName, checkName, vbTextCompare) Then
doesTableExist = True
Exit For
End If
Next
End Function
TIA.
- Paul Schrum
I am linking tables at startup, and I need to block the linking of
tables which have already been linked.
I accomplish the link with lines like this:
DoCmd.TransferDatabase acLink, "Microsoft Access", _
dbName, acTable, "tbl_tasks", "tbl_tasks"
In which dbName is something like "C:\db\tasks.mdb"
In order to prevent the linking of a table which has already been
linked, I want to wrap the above command in an if-block like so:
if doesTableExist("tbl_tasks") = False then
DoCmd.TransferDatabase acLink, "Microsoft Access", _
dbName, acTable, "tbl_tasks", "tbl_tasks"
end if
I am attempting to implement the Function doesTableExist now, but my
approach, it turns out, is unacceptably slow. I need advice on the
best, fastest way to block Access from linking a given table if the
tablename already exists.
Here is the code for doesTableExist
Function doesTableExist(tableName As String) As Boolean
Dim i, count As Integer
i = 0
count = CurrentDb.TableDefs.count
Dim checkName As String
doesTableExist = False
For i = 0 To count
checkName = CurrentDb.TableDefs(i).Name ' 7 seconds per
execution
If 0 = StrComp(tableName, checkName, vbTextCompare) Then
doesTableExist = True
Exit For
End If
Next
End Function
TIA.
- Paul Schrum