Datalink properties

S

SAL

Hello,
I have an Access XP project file. When you click on the File menu and then
the connection item, it brings up the Data Link Properties dialog where you
can specify the server that the project connects to. Is there a way to set
this property programmatically?

Is this possible?

S
 
6

'69 Camaro

Hi.
Is there a way to set this property programmatically?

I have an example that will get you started, but this example requires that
the user fill in the blanks in the dialog window, so you'll have to expand
on its capabilities if you don't want the user to set those settings.

1. Set references to the Microsoft ActiveX Data Objects 2.x Library (if it
isn't set already) and the Microsoft OLE DB Service Component 1.0 Type
Library.
2. Create a CommandButton on a Form and name it DataLinkBtn.
3. Copy and paste the following code into the Form's code module, then save
and compile:

Private Sub DataLinkBtn_Click()

On Error GoTo ErrHandler

Dim MSDASCObj As MSDASC.DataLinks
Dim cn As ADODB.Connection

Set MSDASCObj = New MSDASC.DataLinks
Set cn = New ADODB.Connection
MSDASCObj.PromptEdit cn

cn.Open
MsgBox "Connection opened successfully."
cn.Close

CleanUp:

Set cn = Nothing
Set MSDASCObj = Nothing

Exit Sub

ErrHandler:

MsgBox "Error in DataLinkBtn_Click( ) in " & vbCrLf & Me.Name & " form."
& _
vbCrLf & "Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
GoTo CleanUp
End Sub


HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
S

SAL

Gunny, thank you that is helpful.

My scenario includes the user selecting either the local instance of SQL
Server or a remote server from a list. Is there a way to pass this thing a
fully configured connection object?

S
 
6

'69 Camaro

Hi.
Is there a way to pass this thing a fully configured connection object?

Assign it to the cn variable. That's a Connection Object. Assign it prior
to the following line of code:

MSDASCObj.PromptEdit cn

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
S

SAL

The code runs fine but it doesn't seem to actually change the connection of
the MS Access database. I open a form and it's still showing the database to
the original server. I changed a record in the alternate server and it's not
showing that data.
What am I missing here?

S
 
S

SAL

Okay, just in case there's someone else out there that wants to know how to
do this, look at the kb article below for how to change the Datalink
properties without popping up the Datalinks dialog box:
http://support.microsoft.com/kb/299297

HTH somebody out there. I sure struggled with it.
I changed the subject line above so google could find it under those terms.

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top