使用VB6

现在,我正在使用软件中的浏览按钮选择文本文件,然后将其转换为MDB(访问)。我不想选择文本文件。

一旦我将软件安装在任何系统中,文本文件应在指定路径中自动选择。然后,文本文件自动将其转换为MDB。一旦转换为MDB

VB代码将文本转换为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

上面的代码正在用于用于MDB转换的文本。但是我需要在不使用浏览按钮的情况下自动转换文本文件。

例如

MDB名称IS - history.mdb和表名是 - event.mdb

我在我的软件中设置了这样的路径“ c: newFolder”

在上面的文件夹中,文本文件将带有不同的名称。可能是每天的文本文件将出现10至20个文本文件,其中有新的不同名称。我也无法给出文本文件名。我只需要像(*.txt)这样的扩展名。

安装软件后,该软件应从C: NewFolder中选择文本文件,然后将其自动转换为MDB,然后将文本文件转换后,文本文件应自动删除。

预期输出

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.

对于将文本转换为具有代码的MDB AM,对于自动选择文本文件,我需要示例代码或IDEA

是VB6的新手,任何人都可以考虑一下如何做到这一点。或任何人都可以发布示例代码以自动选择文本文件。

请。

有帮助吗?

解决方案

基本代码会从中看一些东西:

      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

上面的代码假设在您的C: newFolder中,您只有 *.txt文件,而没有其他文件或文件夹。

Hth

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top