L
LarryP
The Environment: Windows XP/Access 2003
My database uses two linked, pipe-delimited text files -- one is current
week data, one is prior week, with a new file being created weekly. Need
code to reset the links each time a new file comes out, so the "new" table in
Access links to the newly generated source file and the "prior" table now
links to the one from the previous week. Following code, though, fails. For
awhile I was getting an "object not current" error as soon as I tried to do
anything using tdfLinked, but somehow I apparently cured that. Now when it
hits the Refresh line it tells me that c:\PR111505.txt is not a valid path.
(that's an example of what my source file names look like -- the user selects
the two appropriate files on a form, and the filepathnames are passed to my
procedure.) I guess I can't see the forest for the trees here -- what am I
doing wrong?
Private Sub RefreshLinks(strPriorFile As String, strNewFile As String)
Dim dbsCurrent As Database, tdfLinked As TableDef
Set dbsCurrent = CurrentDb
Set tdfLinked = dbsCurrent.TableDefs("PIRPrior")
tdfLinked.Connect =
"Text;DSN=PIRLinkPrior;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=437;DATABASE=" & strPriorFile
tdfLinked.RefreshLink
Set tdfLinked = CurrentDb.TableDefs("PIRNew")
tdfLinked.Connect =
"Text;DSN=PIRLinkNew;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=437;DATABASE="
& strNewFile
tdfLinked.RefreshLink
Set tdfLinked = Nothing
End Sub
My database uses two linked, pipe-delimited text files -- one is current
week data, one is prior week, with a new file being created weekly. Need
code to reset the links each time a new file comes out, so the "new" table in
Access links to the newly generated source file and the "prior" table now
links to the one from the previous week. Following code, though, fails. For
awhile I was getting an "object not current" error as soon as I tried to do
anything using tdfLinked, but somehow I apparently cured that. Now when it
hits the Refresh line it tells me that c:\PR111505.txt is not a valid path.
(that's an example of what my source file names look like -- the user selects
the two appropriate files on a form, and the filepathnames are passed to my
procedure.) I guess I can't see the forest for the trees here -- what am I
doing wrong?
Private Sub RefreshLinks(strPriorFile As String, strNewFile As String)
Dim dbsCurrent As Database, tdfLinked As TableDef
Set dbsCurrent = CurrentDb
Set tdfLinked = dbsCurrent.TableDefs("PIRPrior")
tdfLinked.Connect =
"Text;DSN=PIRLinkPrior;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=437;DATABASE=" & strPriorFile
tdfLinked.RefreshLink
Set tdfLinked = CurrentDb.TableDefs("PIRNew")
tdfLinked.Connect =
"Text;DSN=PIRLinkNew;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=437;DATABASE="
& strNewFile
tdfLinked.RefreshLink
Set tdfLinked = Nothing
End Sub