yasanthax
asked on
On an access2007 databse, switch between a Access backend and SQL backend.
Hi
I currently have DAO code to determine a connection path for a Access backend. I need to connect to a SQL backend I have not created yet. I was wondering if a connection string can be used similarly for a SQL backend (and Access backend) and assume the DAO code for updating links can be changed to ADODB? Can anyone please advise?
Public Const DB_String_Dev As String = "DSN=MS Access Database;DBQ=C:\Users\MYSE LF\Desktop \PUDA_DB_b e.accdb;De faultDir=C :\Users\MY SELF\Deskt op;DriverI d=25;FIL=M S Access;MaxBufferSize=2048; PageTimeou t=5;"
Public Const RELEASE_STAGE As String = "DEV"
Public Function DBConVer(DB_Con_Ver As String) As String
DBConVer = DB_String_Dev
End Function
'------------------------- ---DAO ---Update link module
Private Sub UpdateTblLinks()
Dim CurDB As DAO.Database
Dim tdfLinked As DAO.TableDef
Dim TBDef As DAO.TableDef
Dim strPath As String
On Error GoTo UpdateTblLinks_Err
strPath = DBConVer(RELEASE_STAGE)
Set CurDB = CurrentDb
For Each TBDef In CurDB.TableDefs
If Len(TBDef.Connect) > 0 Then
TBDef.Connect = ";Database" & _
Right(Left(strPath, InStr(strPath, "DefaultDir=") - 2), Len(Left(strPath, InStr(strPath, "DefaultDir=") - 2)) - InStr(strPath, "DBQ=") - 2)
TBDef.RefreshLink
End If
UpdateTblLinks_Resume:
Next TBDef
'We've reached the end of the tables, so we can gracefully exit
GoTo UpdateTblLinks_Exit
UpdateTblLinks_Err:
If Err.Number = 3011 Then
'clear the error and
Err.Clear
'resume execution of the loop
GoTo UpdateTblLinks_Resume
Else
MsgBox Err.Description
End If
UpdateTblLinks_Exit:
Set CurDB = Nothing
Set tdfLinked = Nothing
Set TBDef = Nothing
End Sub
I currently have DAO code to determine a connection path for a Access backend. I need to connect to a SQL backend I have not created yet. I was wondering if a connection string can be used similarly for a SQL backend (and Access backend) and assume the DAO code for updating links can be changed to ADODB? Can anyone please advise?
Public Const DB_String_Dev As String = "DSN=MS Access Database;DBQ=C:\Users\MYSE
Public Const RELEASE_STAGE As String = "DEV"
Public Function DBConVer(DB_Con_Ver As String) As String
DBConVer = DB_String_Dev
End Function
'-------------------------
Private Sub UpdateTblLinks()
Dim CurDB As DAO.Database
Dim tdfLinked As DAO.TableDef
Dim TBDef As DAO.TableDef
Dim strPath As String
On Error GoTo UpdateTblLinks_Err
strPath = DBConVer(RELEASE_STAGE)
Set CurDB = CurrentDb
For Each TBDef In CurDB.TableDefs
If Len(TBDef.Connect) > 0 Then
TBDef.Connect = ";Database" & _
Right(Left(strPath, InStr(strPath, "DefaultDir=") - 2), Len(Left(strPath, InStr(strPath, "DefaultDir=") - 2)) - InStr(strPath, "DBQ=") - 2)
TBDef.RefreshLink
End If
UpdateTblLinks_Resume:
Next TBDef
'We've reached the end of the tables, so we can gracefully exit
GoTo UpdateTblLinks_Exit
UpdateTblLinks_Err:
If Err.Number = 3011 Then
'clear the error and
Err.Clear
'resume execution of the loop
GoTo UpdateTblLinks_Resume
Else
MsgBox Err.Description
End If
UpdateTblLinks_Exit:
Set CurDB = Nothing
Set tdfLinked = Nothing
Set TBDef = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't know if it is necessary but in the apps where I support switching between Jet/ACE and SQL Server on the fly, I delete the current linked tables and then add them again from the other source. This requires that I keep a local table with the local and remote names of each table I want to link to. I don't have the code handy but will post it later if your problem isn't resolved. I had another app where it needed to switch between several development and production databases and since those were all SQL Server, I just kept the connection strings in a table and when the user picked his environment, refreshed them using a loop similar to what you have.
Curious why you awarded a B grade, without any request for additional help? That's not consistent with EE grading policy:
http://support.experts-exchange.com/customer/portal/articles/481419-what-grade-should-i-award-?b_id=44
http://support.experts-exchange.com/customer/portal/articles/481419-what-grade-should-i-award-?b_id=44