473,467 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help with Re-linking tables to SQL server

I have this code written that lets me relink my SQL server links to a
specific SQL server (via a different DSN). The problem I have is that I
have to enter the password when I run it. Can any one show me how to
code the password in so the user doesn't have to deal wtih that?
Thanks. Here's the code:

---- BEGIN CODE

Public Sub ReConnectTables()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim td2 As DAO.TableDef
Dim strTable As String
Dim strMsg As String

On Error GoTo lblErr
strMsg = "Tables were relinked successfully."

' Get rid of any old links.
'Call DeleteLinks

' Create a recordset to obtain server object names.
Set db = CurrentDb
' Walk through list of tables and create the links.
For Each tdf In CurrentDb.TableDefs
With tdf
' Delete only SQL Server tables.
If (.Attributes And dbAttachedODBC) = dbAttachedODBC And
Not tdf.Name = "tblTableNames" Then

DoCmd.Rename "bak_" & tdf.Name, acTable, tdf.Name
strTable = tdf.Name '"dbo." ' rst!SQLTable
' Create a new TableDef object.
Set td2 = db.CreateTableDef(strTable)
' Set the Connect property to establish the link.
td2.Connect = "ODBC;DSN=MyDSN;" & _
"Description=My Target Server;" & _
"UID=MyUserID;APP=Microsoft Office 2003;" &
_
"WSID=MyWorkStationID;DATABASE=TargetDB;" &
_
"TABLE=dbo." & strTable

td2.SourceTableName = strTable
' Append to the database's TableDefs collection.
db.TableDefs.Append td2
'DELETE old table
DBEngine(0)(0).Execute "DROP TABLE [" & "bak_" &
tdf.Name & "]"

End If
End With
Next tdf

lblExit:
Set tdf = Nothing
Set db = Nothing
MsgBox strMsg, , "Link SQL Tables"
Exit Sub

lblErr:
Select Case Err
Case Else
ErrMsgFunction()
Resume lblExit
End Select
Resume
End Sub

---- END CODE

Nov 21 '06 #1
3 2133
javelin,
Try adding the password to your connection string... I.E.:
td2.Connect = "ODBC;DSN=MyDSN;" & _
"Description=My Target Server;" & _
"UID=MyUserID;PWD=password;APP=Microsoft Office 2003;" &
_
"WSID=MyWorkStationID;DATABASE=TargetDB;" &
_
"TABLE=dbo." & strTable
Replace the word password with the appropriate values.

Hope this helps

javelin wrote:
I have this code written that lets me relink my SQL server links to a
specific SQL server (via a different DSN). The problem I have is that I
have to enter the password when I run it. Can any one show me how to
code the password in so the user doesn't have to deal wtih that?
Thanks. Here's the code:

---- BEGIN CODE

Public Sub ReConnectTables()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim td2 As DAO.TableDef
Dim strTable As String
Dim strMsg As String

On Error GoTo lblErr
strMsg = "Tables were relinked successfully."

' Get rid of any old links.
'Call DeleteLinks

' Create a recordset to obtain server object names.
Set db = CurrentDb
' Walk through list of tables and create the links.
For Each tdf In CurrentDb.TableDefs
With tdf
' Delete only SQL Server tables.
If (.Attributes And dbAttachedODBC) = dbAttachedODBC And
Not tdf.Name = "tblTableNames" Then

DoCmd.Rename "bak_" & tdf.Name, acTable, tdf.Name
strTable = tdf.Name '"dbo." ' rst!SQLTable
' Create a new TableDef object.
Set td2 = db.CreateTableDef(strTable)
' Set the Connect property to establish the link.
td2.Connect = "ODBC;DSN=MyDSN;" & _
"Description=My Target Server;" & _
"UID=MyUserID;APP=Microsoft Office 2003;" &
_
"WSID=MyWorkStationID;DATABASE=TargetDB;" &
_
"TABLE=dbo." & strTable

td2.SourceTableName = strTable
' Append to the database's TableDefs collection.
db.TableDefs.Append td2
'DELETE old table
DBEngine(0)(0).Execute "DROP TABLE [" & "bak_" &
tdf.Name & "]"

End If
End With
Next tdf

lblExit:
Set tdf = Nothing
Set db = Nothing
MsgBox strMsg, , "Link SQL Tables"
Exit Sub

lblErr:
Select Case Err
Case Else
ErrMsgFunction()
Resume lblExit
End Select
Resume
End Sub

---- END CODE
Nov 22 '06 #2
Hi Jevelin,

You can try my tool :
http://www.logicielappui.com/tips/Ac...ginMDB_SQL.zip
Best regards

Robert Simard
Logipro
http://www.logicielappui.com/tips
"javelin" <go*************@spamgourmet.coma écrit dans le message de news:
11**********************@h54g2000cwb.googlegroups. com...
>I have this code written that lets me relink my SQL server links to a
specific SQL server (via a different DSN). The problem I have is that I
have to enter the password when I run it. Can any one show me how to
code the password in so the user doesn't have to deal wtih that?
Thanks. Here's the code:

---- BEGIN CODE

Public Sub ReConnectTables()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim td2 As DAO.TableDef
Dim strTable As String
Dim strMsg As String

On Error GoTo lblErr
strMsg = "Tables were relinked successfully."

' Get rid of any old links.
'Call DeleteLinks

' Create a recordset to obtain server object names.
Set db = CurrentDb
' Walk through list of tables and create the links.
For Each tdf In CurrentDb.TableDefs
With tdf
' Delete only SQL Server tables.
If (.Attributes And dbAttachedODBC) = dbAttachedODBC And
Not tdf.Name = "tblTableNames" Then

DoCmd.Rename "bak_" & tdf.Name, acTable, tdf.Name
strTable = tdf.Name '"dbo." ' rst!SQLTable
' Create a new TableDef object.
Set td2 = db.CreateTableDef(strTable)
' Set the Connect property to establish the link.
td2.Connect = "ODBC;DSN=MyDSN;" & _
"Description=My Target Server;" & _
"UID=MyUserID;APP=Microsoft Office 2003;" &
_
"WSID=MyWorkStationID;DATABASE=TargetDB;" &
_
"TABLE=dbo." & strTable

td2.SourceTableName = strTable
' Append to the database's TableDefs collection.
db.TableDefs.Append td2
'DELETE old table
DBEngine(0)(0).Execute "DROP TABLE [" & "bak_" &
tdf.Name & "]"

End If
End With
Next tdf

lblExit:
Set tdf = Nothing
Set db = Nothing
MsgBox strMsg, , "Link SQL Tables"
Exit Sub

lblErr:
Select Case Err
Case Else
ErrMsgFunction()
Resume lblExit
End Select
Resume
End Sub

---- END CODE

Nov 22 '06 #3
That worked. It didn't work the first 200 tries, for some reason.

Thanks for the quick (and accurate) reply.

stejol377 wrote:
javelin,
Try adding the password to your connection string... I.E.:
td2.Connect = "ODBC;DSN=MyDSN;" & _
"Description=My Target Server;" & _
"UID=MyUserID;PWD=password;APP=Microsoft Office 2003;" &
_
"WSID=MyWorkStationID;DATABASE=TargetDB;" &
_
"TABLE=dbo." & strTable

Replace the word password with the appropriate values.

Hope this helps

javelin wrote:
I have this code written that lets me relink my SQL server links to a
specific SQL server (via a different DSN). The problem I have is that I
have to enter the password when I run it. Can any one show me how to
code the password in so the user doesn't have to deal wtih that?
Thanks. Here's the code:

---- BEGIN CODE

Public Sub ReConnectTables()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim td2 As DAO.TableDef
Dim strTable As String
Dim strMsg As String

On Error GoTo lblErr
strMsg = "Tables were relinked successfully."

' Get rid of any old links.
'Call DeleteLinks

' Create a recordset to obtain server object names.
Set db = CurrentDb
' Walk through list of tables and create the links.
For Each tdf In CurrentDb.TableDefs
With tdf
' Delete only SQL Server tables.
If (.Attributes And dbAttachedODBC) = dbAttachedODBC And
Not tdf.Name = "tblTableNames" Then

DoCmd.Rename "bak_" & tdf.Name, acTable, tdf.Name
strTable = tdf.Name '"dbo." ' rst!SQLTable
' Create a new TableDef object.
Set td2 = db.CreateTableDef(strTable)
' Set the Connect property to establish the link.
td2.Connect = "ODBC;DSN=MyDSN;" & _
"Description=My Target Server;" & _
"UID=MyUserID;APP=Microsoft Office 2003;" &
_
"WSID=MyWorkStationID;DATABASE=TargetDB;" &
_
"TABLE=dbo." & strTable

td2.SourceTableName = strTable
' Append to the database's TableDefs collection.
db.TableDefs.Append td2
'DELETE old table
DBEngine(0)(0).Execute "DROP TABLE [" & "bak_" &
tdf.Name & "]"

End If
End With
Next tdf

lblExit:
Set tdf = Nothing
Set db = Nothing
MsgBox strMsg, , "Link SQL Tables"
Exit Sub

lblErr:
Select Case Err
Case Else
ErrMsgFunction()
Resume lblExit
End Select
Resume
End Sub

---- END CODE
Nov 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
2
by: Patrick Lim | last post by:
Here is the problem: I have written a non-modal frame class in Java for displaying help text when a user is using an application. It works as desired in that if the user selects "help" again,...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
2
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
0
by: tbatwork828 | last post by:
If you were like me trying to figure out how to launch context sensitive help topic by the context id, here is the link: http://weblogs.asp.net/kencox/archive/2004/09/12/228349.aspx and if...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
0
by: Yabedabe | last post by:
Hello there, I have a strange problem (possible bug?) to display two HTML Help files at the same time. To reproduce this problem. Create a new VB.Net solution. Place two buttons on the form....
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.