LISTING 2: Sub Main Sub Main() Callout A Dim oDataLink As New MSDASC.DataLinks Dim oConn As ADODB.Connection Callout A Dim oDialog As Object Dim bReturn As Boolean Dim bByteOutput() As Byte Dim sTemp As String On Local Error GoTo Data_Link_Error Callout B ' Display the Data Link Dialog Set oConn = oDataLink.PromptNew Callout B ' Don't display the save dialog on Cancel If oConn Is Nothing Then 'If oConn.ConnectionString = vbNullString Then Set oDataLink = Nothing Set oConn = Nothing Exit Sub Else Callout C 'Prompt to save into a UDL file Set oDialog = CreateObject("MSComDlg.CommonDialog.1") oDialog.Filter = "Data Link Files (*.udl) | *.udl" oDialog.ShowSave Callout C ' Don't write the file on cancel If oDialog.FileName <> "" Then Callout D Open oDialog.FileName For Binary As #1 Put #1, , &HFEFF sTemp = "[oledb]" & vbCrLf bByteOutput = sTemp Put #1, , bByteOutput sTemp = "; Everything after this line is an OLE DB initstring" & vbCrLf ReDim bByteOutput(Len(sTemp) * 2) As Byte bByteOutput = sTemp Put #1, , bByteOutput ReDim bByteOutput(Len(oConn.ConnectionString & vbCrLf) * 2) As Byte bByteOutput = oConn.ConnectionString & vbCrLf Put #1, , bByteOutput Close #1 Callout D End If Set oDialog = Nothing End If Set oDataLink = Nothing Set oConn = Nothing Exit Sub Data_Link_Error: MsgBox "Error #" & Err.Number & vbCrLf & _ Err.Description & vbCrLf & Err.Source End Sub