views:

97

answers:

1

Using VB6

Now I am using a Browse button in my software to select the text file, then it is converted in to mdb (access). I don’t want to select the text file.

Once I installed my software in any system, the text file should automatically select in a specified path. Then the text file automatically converts into mdb. Once converted in to mdb then

Vb Code for converting text to mdb.

Dim db As Database, tbl As TableDef
Set db = DBEngine.OpenDatabase(App.Path & "\History.mdb")
Set tbl = db.CreateTableDef("Temp")
tbl.Connect = "Text;database=" & App.Path & "/ConvTemp/"
tbl.SourceTableName = strOutput & ".txt"
db.TableDefs.Append tbl
db.Execute "Select Temp.ID, Temp.IDTerminal, Temp.Reader, Temp.Date, Temp.Time, Temp.Cardnumber into  " & strOutput & "  from Temp"
db.TableDefs.Delete ("Temp")
db.Close
MsgBox strOutput
sql2 = "insert into events select * from " & strOutput & ""
If rs.State = 1 Then rs.Close
rs.Open sql2, Cn, adOpenStatic, adLockOptimistic
Set tbl = Nothing
Set db = Nothing

Above code is working for text to mdb conversion. But I need to convert the text file automatically without using browse button.

For Example

MDB Name is – History.mdb and table name is – event.mdb

I set a path like this “C:\NewFolder” In my software

In the above folder, the text file will appear with different names. May be per day text file will appear 10 to 20 text files with new different names. I cannot able to give the text file name also. I have to give only the extension like (*.txt).

Once I installed my software, the Software should select the text file from c:\NewFolder, then it automatically converts in to mdb, after converted the text file the text file should delete automatically.

Expected Output

Once I installed my software in any system, the software should select the text file from the specified folder, then the text file convert into mdb. Once converted, the text files automatically delete from the specified path.

For converting text to mdb am having the code, for automatically selecting the text file I need a sample code or idea’s

Am new to VB6, Can any one give some idea how to do this. Or can any post a sample code for automatically selection of text file.

Please.

+1  A: 

Basic code would look something down the lines of this:

      Dim filename As String
      filename = Dir$("C:\NewFolder\*.txt", vbDirectory)
      Do While filename <> ""

        Debug.Print filename

        'This line will delete the file as you asked
        'but to make sure if the file has been converted to mdb
        'is solely your code's responsibility

        Kill "C:\NewFolder\" & filename

        filename = Dir$
      Loop

The above code assumes that in your C:\NewFolder you will only have *.txt files and no other files or folders.

HTH

Anand
@Anand. So No need give Any other, Once I installed the software, This code will automatically select a file. Once converted, then File will automatically delete.
Gopal
This code will automatically select file => "YES". Conversion part is something you'll have to merge in the code. Once converted, the File will automatically delete => "YES"
Anand
@Anand. once I Created a Setup, Then I installed the software in any other system. I have to do any thing, otherwise it will automatically do all(means selecting a text file, conversion, deletion. Bcoz Most of my software i have to run my software, then only it will do some thing. No I don't want to do any thing. Once installed to other system. It will do automatically. where i have to write a code. In form load (or) any other. plz
Gopal
Sorry but I don't understand what exactly you are trying to achieve. Basically if you put the code in Form Load and call that Form it will run the code, converting all the text files to mdb files and deleting the text files. But you will have to run the software somehow, other option would be to create an exe file for the above code and add it to the task scheduler which will automatically run it at the time interval specified.
Anand
@Anand - Now am getting, So If am having three kind of files like *.txt, *.mis, *.fis file means. How to give in filename. Can you plz.
Gopal