PDA

View Full Version : change connect link



DJEZ
02-19-2015, 07:47 AM
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:\Document s and Settings\DAVID_JEZEQUEL\Bureau
tbl.Connect = "Text;DSN=CLASSEUR2 SpÈcification d'attache;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=850;DATABASE=C:\Document s and Settings\DAVID_JEZEQUEL\Bureau"
tbl.RefreshLink

mancubus
02-26-2015, 12:33 AM
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.