Image of Navigational Panel mapped to Contents / Home / Search Finding Syntax in VB4.0
Tech Support Question

Image of Line Break

Q. Here is a command in Access 7.0 that will do exactly what I'm trying to do. In the database I've created, I wrote a module that contains the importing process. It uses a command called "DoCmd", and a sub-command called "TransferText". Here is what my code looks like:

  Function impcell()
  Dim yest$, f$
  yest$ = Format(Now() - 1, "yymmdd")
  f$ = Mid$(yest$, 3, 4) & Mid$(yest$, 1, 2)
  DoCmd.TransferText acImportDelim, "Cell Results Import Specification", 
                                    "cell", "F:\DBMS\RAWDATA\PARSED\cr" & f$ & ".csv"

  End Function

The rest of the code just specifies the name of the file.

I've looked for the Do.Cmd syntax in VB 4.0, but can't find it. Does it exist? If not, can I call this function from VB 4.0 and run it on a machine that has VB 4.0 but not Access?

From: Jeff Motter
Email: jmotter@fgi.net

A. The syntax you are referring to here is definitely Access specific. It executes internal Access commands from Access Basic, much like you would from an Access macro. Because VB is not Access you do not have the commands associated with the Access environment to shortcircuit some tasks, in this case you do not have access to Access' import and export functionality. Basically this means you have to write some code. DoCmd TransferText was a quick way to call the Access import/export tools, which you don't have in VB.

However, VB has some very cool text file handling functions and you can fairly easily write something that will do the same job. The first step is to make yourself familiar with the VB Open statement used to open files for various sorts of access. Once you have your file open you can read it in using whatever method you choose to code. As an example your code will likely end up looking something like this:

      Dim hFile as Integer
      Dim sName as String
      Dim iAge as Integer
	
      hFile = FreeFile      ' Get a free file handle
      Open "c:\myfile.csv" For Input Access Read As hFile ' Open the file
      Do While not EOF(hFile)
            Input #hFile, sName, iAge
            '-- Do something with sName and iAge...
      Loop
      Close #hFile          ' Close the file once we reach the end

Yes, it involves more coding, but it does give you better control. And after all, isn't that what programming is about? Writing some good solid code, not relying on a good solid obscure feature that is not supported in future versions?

I hope this helps you out, Jeff. And remember, don't despair it's your logic not your code that you need to keep from version to version.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]