I'm a pretty sure about the syntax because it works fine on access2007I would say the clue is in the error message. Maybe focus on your syntax and see if you're using Table2 in the right argument.
I'm a pretty sure about the syntax because it works fine on access2007I would say the clue is in the error message. Maybe focus on your syntax and see if you're using Table2 in the right argument.
What does your code look like for IsTable()?the code of mine is posted above, the database located here strPath = Application.CurrentProject.Path & "\idcard.mdb"
Function syntax doesn't usually change between versions. So, if the same syntax doesn't work in one version but does on another, then what you want to check is the environment. For example, the error message specifically mentioned "Table2," try and see if there's something different about Table2 between 2007 and 2010.I'm a pretty sure about the syntax because it works fine on access2007
this function is just to check if the table is existing or noWhat does your code look like for IsTable()?
Can we still see it please?this function is just to check if the table is existing or no
I don't know what's wrong .. as u c the table2 is existing in the second databaseFunction syntax doesn't usually change between versions. So, if the same syntax doesn't work in one version but does on another, then what you want to check is the environment. For example, the error message specifically mentioned "Table2," try and see if there's something different about Table2 between 2007 and 2010.
sureCan we still see it please?
If you step through the code, which line is getting highlighted when you debug?I don't know what's wrong .. as u c the table2 is existing in the second database View attachment 86758
Thanks. Since I am not familiar with your database and cannot see what you're looking at, we need to ask for clarifications and verify places where we would check anyway.sure
Option Compare Database
Option Explicit
Public Function IsTable(sTblName As String) As Boolean
'does table exists and work ?
'note: finding the name in the TableDefs collection is not enough,
' since the backend might be invalid or missing
On Error GoTo hell
Dim x
x = DCount("*", sTblName)
IsTable = True
Exit Function
hell:
Debug.Print Now, sTblName, Err.Number, Err.Description
IsTable = False
'MsgBox "" & IsTable
End Function
Public Function CreateLinkedTable(ByVal strLinkedTableName As String, _
ByVal strSourceTable As String, _
ByVal strSourceDatabase As String) As Boolean
Dim rs As DAO.Recordset, ok As Boolean
Dim db As DAO.Database
Dim td As DAO.TableDef
Set db = CurrentDb
'check if source database exists
ok = (Len(Dir$(strSourceDatabase)) > 0)
If ok Then
'check if table exists
On Error Resume Next
Set rs = db.OpenRecordset( _
"select * from [" & strSourceTable & "] In '" & strSourceDatabase & "'")
ok = (Err.Number = 0)
Err.Clear
Set rs = Nothing
If ok Then
'delete old table link, if already exists
DoCmd.DeleteObject Objecttype:=acTable, ObjectName:=strLinkedTableName
Application.RefreshDatabaseWindow
Err.Clear
On Error GoTo 0
Set td = db.CreateTableDef(strLinkedTableName)
With td
.Connect = ";DATABASE=" & strSourceDatabase
.SourceTableName = strSourceTable
End With
db.TableDefs.Append td
Set td = Nothing
db.TableDefs.Refresh
Application.RefreshDatabaseWindow
End If
End If
Set db = Nothing
CreateLinkedTable = ok
End Function
there is no highlighted line at all , only that error msg says Microsoft access unable.. then continue open the other forms normally but no linked tableIf you step through the code, which line is getting highlighted when you debug?
no only link with table2 as shown in this line of codethe linking code you posted is supposed to create a linked table for all the tables in the BE, correct?
Thank u so much ^_^ finally it works yaaaaayou may try also this modified version of your CreateLinkedTable() function:
to use it:
Call CreateLinkedTable("Table2", "Table2", Application.CurrentProject.Path & "\idcard.mdb")
Code:Public Function CreateLinkedTable(ByVal strLinkedTableName As String, _ ByVal strSourceTable As String, _ ByVal strSourceDatabase As String) As Boolean Dim rs As DAO.Recordset, ok As Boolean Dim db As DAO.Database Dim td As DAO.TableDef Set db = CurrentDb 'check if source database exists ok = (Len(Dir$(strSourceDatabase)) > 0) If ok Then 'check if table exists On Error Resume Next Set rs = db.OpenRecordset( _ "select * from [" & strSourceTable & "] In '" & strSourceDatabase & "'") ok = (Err.Number = 0) Err.Clear Set rs = Nothing If ok Then 'delete old table link, if already exists DoCmd.DeleteObject Objecttype:=acTable, ObjectName:=strLinkedTableName Application.RefreshDatabaseWindow Err.Clear On Error GoTo 0 Set td = db.CreateTableDef(strLinkedTableName) With td .Connect = ";DATABASE=" & strSourceDatabase .SourceTableName = strSourceTable End With db.TableDefs.Append td Set td = Nothing db.TableDefs.Refresh Application.RefreshDatabaseWindow End If End If Set db = Nothing CreateLinkedTable = ok End Function
Hi. Congratulations! Glad to hear you got it sorted out. Sorry I wasn't much help.Thank u so much ^_^ finally it works yaaaaa
Thank u too, u also helped me a lot by tracking the problem ^_^Hi. Congratulations! Glad to hear you got it sorted out. Sorry I wasn't much help.
Good luck with your project.