Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2004, 12:47 PM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change File in DTS?

I am trying to change the file that is imported using DTS. Here is my code so far:
[vb]
'change DTS Package
        Dim oPKG As DTS.Package, oStep As DTS.Step
        oPKG = New DTS.Package
        Dim oConn As DTS.Connection

        Dim sServer As String, sUsername As String, sPassword As String
        Dim sPackageName As String, sMessage As String
        Dim lErr As Long, sSource As String, sDesc As String

        ' Set Parameter Values
        sServer = "CRSERVER"
        sUsername = "brenda"
        sPassword = "g_Password"
        sPackageName = "ImportNewAccurintDataHigh"

        ' Load Package
        oPKG.LoadFromSQLServer(sServer, sUsername, sPassword, _
            DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrus tedConnection, , , , sPackageName)

        'Set Filename
        Dim ofd As New OpenFileDialog
        With ofd
            .Title = "Choose An Excel File"
            .InitialDirectory = "C:\Accurint\"
            .Filter = "XLS (*.xls)|*.xls|All files (*.*)|*.*"
            .FilterIndex = 2
            .RestoreDirectory = True
            .Multiselect = False
        End With
        ofd.ShowDialog()
        oPKG.Connections.Item("Connection 1").DataSource = ofd.FileName
        oConn = Nothing

        ' Set Exec on Main Thread
        For Each oStep In oPKG.Steps
            oStep.ExecuteInMainThread = True
        Next

        ' Execute
        oPKG.Execute()

        ' Get Status and Error Message
        For Each oStep In oPKG.Steps
            If oStep.ExecutionResult = DTS.DTSStepExecResult.DTSStepExecResult_Failure Then
                oStep.GetExecutionErrorInfo(lErr, sSource, sDesc)
                sMessage = sMessage & "Step """ & oStep.Name & _
                    """ Failed" & vbCrLf & _
                    vbTab & "Error: " & lErr & vbCrLf & _
                    vbTab & "Source: " & sSource & vbCrLf & _
                    vbTab & "Description: " & sDesc & vbCrLf & vbCrLf
            Else
                sMessage = sMessage & "Step """ & oStep.Name & _
                    """ Succeeded" & vbCrLf & vbCrLf
            End If
        Next

        oPKG.UnInitialize()

        oStep = Nothing
        oPKG = Nothing

        ' Display Results
        MsgBox(sMessage)
[/vb]

It is not changing the file though. It is just keeping the same file that is saved in the package already. Anyone have any ideas why?

__________________
Brenda

If it weren't for you guys, where would I be?
 
Old June 24th, 2005, 04:55 PM
Authorized User
 
Join Date: Jun 2003
Posts: 54
Thanks: 2
Thanked 0 Times in 0 Posts
Default

I started troubleshooting this and ran into some problems even before I got to the DTS stuff.

You might want to look at the Help File on FileDialog. This example will give you an idea of the syntax:

Dim ofd As FileDialog

Set ofd = Application.FileDialog(msoFileDialogOpen)

        With ofd
            .Title = "Choose An Excel File"
            .InitialFileName = "C:\"
            'Add a filter that includes Excel files
            .Filters.Add "Excel file", "*.xls; *.xlt", 1

            .InitialView = msoFileDialogViewDetails
            'Allow the selection of multiple files.
            .AllowMultiSelect = True

            'Declare a variable to contain the path
            'of each selected item. Even though the path is a String,
            'the variable must be a Variant because For Each...Next
            'routines only work with Variants and Objects.
            Dim vrtSelectedItem As Variant


            'Use the Show method to display the File Picker dialog box and return the user's action.
            'The user pressed the action button.
            If .Show = True Then

                'Step through each string in the FileDialogSelectedItems collection.
                For Each vrtSelectedItem In .SelectedItems

                    'vrtSelectedItem is a String that contains the path of each selected item.
                    'You can use any file I/O functions that you want to work with this path.
                    'This example simply displays the path in a message box.

                    MsgBox "The path is: " & vrtSelectedItem

                Next vrtSelectedItem
            'The user pressed Cancel.
            Else
                Exit Sub
            End If '.Show = True
        End With 'ofd

=========
You would substitute my Msgbox with your procedure to run the DTS actions (substitute the names somehow).
I am trying to steer away from passing global variables.

I would like to know what you find out ... I have a DTS package that copies 3 Excel files to a SQL-Server table then proceeds to process them. Everytime, I have to manually go in and change the name of the the 3 DTS elements so that they point to the new (ever changing) Excel files.

I am trying to use VBA in Excel or MS-Access to select the file names, substitute the names, then execute the DTS package.

Thanks,



--- Tom





Similar Threads
Thread Thread Starter Forum Replies Last Post
automating the restoring of dts .bas file dishant57 SQL Server DTS 1 June 6th, 2007 04:18 AM
convert a js file from a asp file - change format jstewie Javascript How-To 0 July 21st, 2005 08:57 AM
Help! DTS to upload an excel file mauro_mtl SQL Server 2000 0 May 28th, 2005 03:41 PM
Executing a DTS package on value change gyno.bell SQL Server DTS 1 March 1st, 2005 02:50 PM
sql7 How can I change the fname for a textfile DTS yogesht194 VB How-To 0 October 14th, 2003 07:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.