Results 1 to 2 of 2
  1. #1
    eric.kung is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    13

    Please help translate below VB code

    Dear All



    I have found a code on the internet, this code was said to able to import all my CSV files into my MS Access everytime I run it by commend or something...

    I have no idea how to read this code... can anybody please help me to translate this and describe what this code can really do?

    Thank you!

    Code:
    Option Compare Database
    Option Explicit
    Sub ScanDisk()
    Dim strX As String
    strX = ListFiles("D:\", True)
    strX = ListFiles("C:\MyDocu~1\", True)
    End Sub
    Function ListFiles(parDir As String, parSubDir As Boolean)
    Dim dbs As Database, rstFileList As Recordset
    Dim strNextName As String, strAttr As String, intRecCount
    As Integer, strExt As String
    Dim Directory(200) As String
    Dim intDirCt As Integer, intSize As Long, dttDateTime As
    Date
    Set dbs = CurrentDb()
    Set rstFileList = dbs.OpenRecordset("tblFiles",
    dbOpenDynaset)
    intDirCt = 0
    strNextName = Dir(parDir, vbDirectory)
    Do While strNextName <> ""
    strAttr = 0
    intSize = 0
    If strNextName <> "pagefile.sys" Then
    strAttr = GetAttr(parDir & strNextName)
    End If
    '    If InStrRev(strNextName, ".") = 0 Then
    strExt = ""
    '    Else
    '        strExt = UCase(Mid(strNextName, 1 + InStrRev
    (strNextName, "."), 3))
    '    End If
    If strNextName <> ".." And strNextName <> "." Then
    If strAttr = 16 Then
    intDirCt = intDirCt + 1
    Directory(intDirCt) = parDir & strNextName
    & "\"
    Else
    intSize = FileLen(parDir & strNextName)
    dttDateTime = FileDateTime(parDir &
    strNextName)
    End If
    End If
    If strExt <> "DLL" And strExt <> "EXE" Then
    Debug.Print parDir, strNextName, strAttr, intSize,
    dttDateTime
    intRecCount = intRecCount + 1
    With rstFileList
    .AddNew
    !FName = strNextName
    !FPath = parDir
    !FSize = intSize
    !FDate = dttDateTime
    !FAttribute = strAttr
    .Update
    End With
    End If
    strNextName = Dir()
    Loop
    If parSubDir Then
    Dim intI As Integer
    For intI = 1 To 50
    If Directory(intI) <> "" Then
    strNextName = ListFiles(Directory(intI), True)
    End If
    Next intI
    End If
    End Function
    Last edited by eric.kung; 08-25-2011 at 06:59 PM. Reason: Problem Solved.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You should do some tutorials on vba. Finding something on the internet and running it is a short term approach at best. Who knows what it may do if you don't know vba.

    Here's a link

    http://www.functionx.com/vbaccess2003/index.htm

    You will benefit by working through the code and learning some vba.

    Good luck.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 AM
  2. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  3. Replies: 0
    Last Post: 09-03-2009, 01:58 PM
  4. Translate English to Spanish
    By marge0513 in forum Import/Export Data
    Replies: 0
    Last Post: 05-28-2009, 10:09 AM
  5. how to translate "row_number"?
    By mfran2002 in forum Queries
    Replies: 0
    Last Post: 09-17-2008, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums