Consulting

Results 1 to 2 of 2

Thread: change connect link

  1. #1
    VBAX Newbie
    Joined
    Feb 2015
    Posts
    1
    Location

    change connect link

    HELLO,
    I manually connected a file named classeur1.csv and I changed the type of some columns. The table name is linked t_externe
    Tomorrow will use the file classeur2.csv.
    How to change the source of the t_externe way of a take classeur2.csv data without deleting t_externe.
    I tried the following code but does not work.
    Set tbl = db.TableDefs("t_externe")
    Debug.Print tbl.Connect
    'return me: Text;DSN=CLASSEUR1 SpÈcification d'attache;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=850;DATABASE=C:\Documents and Settings\DAVID_JEZEQUEL\Bureau
    tbl.Connect = "Text;DSN=CLASSEUR2 SpÈcification d'attache;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=850;DATABASE=C:\Documents and Settings\DAVID_JEZEQUEL\Bureau"
    tbl.RefreshLink

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,645
    welcome to vbax.

    below displays an inputbox with a default value of "CLASSEUR", to input the file name.

    Dim retFile
    Dim strDBase As String, strConnPart As String
    
    strConnPart = " SpÈcification d'attache;FMT=Delimited;HDR=NO;IMEX=1;CharacterSet=850;DATABASE="
    strDBase = "C:\Documents and Settings\DAVID_JEZEQUEL\Bureau"
    retFile = Application.InputBox("Input csv file name to connect to", "DataBase Name", "CLASSEUR", , , , , 2)
    
    If retFile = False Or retFile = "" Then
        MsgBox "You did not input a value or pressed ""Cancel"" button. Quitting..."
        Exit Sub
    End If
    
    tbl.Connect = "Text;DSN=" & retFile & strConnPart & strDBase



    'http://www.instantpages.ltd.uk/ADODB_WP.htm

    There is one final twist. A setting of IMEX = 1 in the container string’s extended property determines whether the ImportMixedType value is honoured. IMEX refers to Import Export mode. There are three possible values. IMEX=0 and IMEX=2 result in ImportMixedTypes being ignored and the default value of ‘MajorityType’is used. IMEX=1 is the only way to ensure ImportMixedTypes=Text is honoured.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •