save folder name to table (1 Viewer)

rio

Registered User.
Local time
Tomorrow, 00:42
Joined
Jun 3, 2008
Messages
124
hi.. I used this module to save the file directory in new created table. This code i got from searching in the google. so the problem is.... how to save the folder name to in that table.

there is a few folder in (CurrentProject.Path & "\Kml Shape File\") :
1. lotname
2. place
3. Hotel


Code:
Private Function FilesAndDetails()
On Error GoTo Err_FilesAndDetails

    Dim rs As Recordset
    Dim vDir As Variant
    Dim FilewPath As String
    
    FilewPath = (CurrentProject.Path & "\Kml Shape File\") 'sPath must end with a back slash, sPath = "C:\Windows\"
    
    CurrentDb.Execute "Delete tTempFiles.* from tFiles;"
    
    Set rs = CurrentDb.OpenRecordset("tFiles")
    
    vDir = Dir(FilewPath & "*.*")
    
    Do Until vDir = ""
        rs.AddNew
        rs!FilePathName = FilewPath & vDir
        rs!FilePath = FilewPath
        [COLOR=Red]rs!FileFolde = ??????????????[/COLOR]
        rs!FileName = vDir
        rs!ModifiedDate = FileDateTime(FilewPath & vDir)
        rs!FileSize = FileLen(FilewPath & vDir)
        rs.Update
        vDir = Dir
    Loop
    
    rs.Close
    Set rs = Nothing

    DoCmd.Requery

Exit_FilesAndDetails:
    Exit Function
    
Err_FilesAndDetails:
    MsgBox Err.Number & " - " & Err.description
    Resume Exit_FilesAndDetails

what should i put at ?????????? (red colour) this part in this code.
 

vbaInet

AWF VIP
Local time
Today, 17:42
Joined
Jan 22, 2010
Messages
26,374
Copying and pasting code into your project without understanding what it does wouldn't help you. This seems to be a simple enough one I think if you really look into it you would understand.

I know you're able ;)
 

rio

Registered User.
Local time
Tomorrow, 00:42
Joined
Jun 3, 2008
Messages
124
thanks... for reply.
i try to understand this code... but the problem is :
1. my English is not so good as u
2. ms access is not my expertise.... (just as hobby)

anyway... i try my best....

there is a few code I understand... how it's function.
I think ... to solve my problem is ... I should understand this code
Code:
vDir = Dir(FilewPath & "*.*")
so can u translate it to simple word.... to make me easily understand it.
what is "." for???
 

vbaInet

AWF VIP
Local time
Today, 17:42
Joined
Jan 22, 2010
Messages
26,374
Remember when you use LIKE in a query and you put the asterisk (*) to find possible matches. Let's say, a criteria was this:

Code:
LIKE *1*
Will give results 010, 210 etc as long as there is a one in the middle.

All that line of code is doing is saving the first file name that matches what Dir returns. So FileWPath & "*.*" could be

FileWPath100.pdf
FileWPath_patter.doc
... etc.

Finally, check the help files in the VBA editor for more explanations.
 

ajetrumpet

Banned
Local time
Today, 11:42
Joined
Jun 22, 2007
Messages
5,638
UMMM...

doesn't the code: currentproject.path give you the ENTIRE address of the file you have open? If it does, I don't think this is possible:
PHP:
FilewPath = (CurrentProject.Path & "\Kml Shape File\")
Looks like you're adding another subdirectory AFTER the file name, unless I'm wrong (which don't doubt that I am, because I'm usually unpopular)
 

vbaInet

AWF VIP
Local time
Today, 17:42
Joined
Jan 22, 2010
Messages
26,374
In actual fact, I think maybe all the OP is trying to do is save those folder names in bold into the table?
so the problem is.... how to save the folder name to in that table.

there is a few folder in (CurrentProject.Path & "\Kml Shape File\") :
1. lotname
2. place
3. Hotel
If that's the case then a recordset isn't need. Just the FileSystem object.

Yes, Adam you're right in thinking that that line is referring to a sub-directory. I would imagine that path already exists. It may also be that those three folders mentioned above are all under the sub-direcory "Kml Shape File".
 

ajetrumpet

Banned
Local time
Today, 11:42
Joined
Jun 22, 2007
Messages
5,638
just thought i would point out the unobvious. remember, my opinion is a devalued one, so don't put much faith in it. :rolleyes:

It's still above the dollar though!
 

ajetrumpet

Banned
Local time
Today, 11:42
Joined
Jun 22, 2007
Messages
5,638
Well, you're doing rather well. Looks like one trades in foreign currencies?:D
yeah, my account is listed on the FOREX under InsultsUnlimited :D

I think I'm gonna cut this thread off before we draw anymore attention buddy. See you in the realm of other cyberspace.
 

rio

Registered User.
Local time
Tomorrow, 00:42
Joined
Jun 3, 2008
Messages
124
Code:
Yes, Adam you're right in thinking that that line is referring to a  sub-directory. I would imagine that path already exists. It may also be  that those three folders mentioned above are all under the sub-direcory  "Kml Shape File".
it's true.... i want to put the name of tree sub folder name (place, lotname and hotel) under folder "Kml Shape File" into table automatically as i put filename
 

rio

Registered User.
Local time
Tomorrow, 00:42
Joined
Jun 3, 2008
Messages
124
How to make this code to show all data including folders not only the file.
Code:
vDir = Dir(FilewPath & "*.*")
i try change it to this :
Code:
vDir = Dir(FilewPath & "**")

still don't work.
 

rio

Registered User.
Local time
Tomorrow, 00:42
Joined
Jun 3, 2008
Messages
124
hi ghudson, I already see it. but for me (as a beginner) it's too complex. ... can u give me any hint..... which part i should concentrate ..... module or form...????

i think in this code:

Code:
Public Function BrowseDirectory(szDialogTitle As String) As String
On Error GoTo Err_BrowseDirectory

    Dim X As Long, bi As BROWSEINFO, dwIList As Long
    Dim szPath As String, wPos As Integer
    
    With bi
        .hOwner = hWndAccessApp
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    
    dwIList = SHBrowseForFolder(bi)
    szPath = Space$(512)
    X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
    
    If X Then
        wPos = InStr(szPath, Chr(0))
        BrowseDirectory = Left$(szPath, wPos - 1)
    Else
        BrowseDirectory = ""
    End If

Exit_BrowseDirectory:
    Exit Function

Err_BrowseDirectory:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_BrowseDirectory

End Function

difficult to understand ..... :eek::eek::eek:
 

Users who are viewing this thread

Top Bottom