|
 |
access thread: Using DoCmd.TransferText without Access open
Message #1 by "mark williams" <mwilliams22@y...> on Wed, 16 Jan 2002 00:31:33
|
|
Hi is it possible to use DoCmd.TransferText when Access is not open.
I have been using the following command to import a CSV file into a access
table from VB
DoCmd.TransferText acImportDelim, "SthgDelimited", etc
The SthgDelimited parameter is the specification name for the set of
options that determines how a text file is imported, exported, or linked.
ie with commas in the case of my CSV file. And I set this file up by using
the Get External Data,File Import option and then saving a file as file
name SthgDelimited, with the required file deliminater in the advanced
option of the wizard.
The problem that I have is when using this command in a VB program the VB
program fails if I do not have Access open at the same time. I receive an
error message saying the text file SthgDelimited doesnt exist.
Is there a way around this as I would like the VB program to work on all
machines and not just those with Access.
many thanks
Mark
Message #2 by frazerg@t... on Wed, 16 Jan 2002 02:25:04
|
|
The DoCmd is a method of the Application object in MSAccess.
To run this from VB you will need to Reference the Microsoft Access 8.0
Object Library or greater. Match the Library to the Access database
version.
Here is some code that should work
Option Explicit
' Declare object variable in declarations section of a module
Dim appAccess As Access.Application
Private Sub Command1_Click()
Dim strDB As String
' Initialize string to database path.
strDB = "C:\Program Files\Microsoft
Office\Office\Samples\Northwind.mdb"
' Return reference to Microsoft Access Application object.
Set appAccess = New Access.Application
' Open database in Microsoft Access.
appAccess.OpenCurrentDatabase strDB
' Import the File.
DoCmd.TransferText
acImportDelim, "MyFileImportSpecification", "MyFile", "C:\MyFile.txt",
False
'Close instance of access
appAccess.CloseCurrentDatabase
' destroy the variable
Set appAccess = Nothing
End Sub
Regards
Greg Frazer
> Hi is it possible to use DoCmd.TransferText when Access is not open.
> I have been using the following command to import a CSV file into a
access
> table from VB
>
> DoCmd.TransferText acImportDelim, "SthgDelimited", etc
>
> The SthgDelimited parameter is the specification name for the set of
> options that determines how a text file is imported, exported, or
linked.
> ie with commas in the case of my CSV file. And I set this file up by
using
> the Get External Data,File Import option and then saving a file as file
> name SthgDelimited, with the required file deliminater in the advanced
> option of the wizard.
>
> The problem that I have is when using this command in a VB program the
VB
> program fails if I do not have Access open at the same time. I receive
an
> error message saying the text file SthgDelimited doesnt exist.
>
> Is there a way around this as I would like the VB program to work on all
> machines and not just those with Access.
>
> many thanks
> Mark
Message #3 by "mark williams" <mwilliams22@y...> on Wed, 16 Jan 2002 08:46:09
|
|
Thanks Greg that is really appreciated, its all working fine now
Mark
|
|
 |