how to browse files and store them to database

mana

Registered User.
Local time
Today, 08:31
Joined
Nov 4, 2014
Messages
265
Hello,

i want to browse the files from a form and then store hem to the database.
i have the following code, i can show the file path to the text box but i don't know how to store the file or how to upload the file to the database.
can you help me please?
thank you

Dim f As Object
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant

Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
'MsgBox "Folder: " & strFolder & vbCrLf & _
'"File: " & strFile
Me.Text6.Value = strFolder & "\" & strFile
Next
End If
Set f = Nothing
 
you would be better having a dedicated folder to store these documents, then in your db, simply store the file name and/or filepath. To store these files in your db will cause it to bloat considerably

With regards your requirements, if the above is not an option, please provide the version of Access you are using - 2007 and later has different options
 
hi,

thank you
i am using access 2010.
can you guide me please more
i couldn't find an appropriate code
thanks
 
how can i store the files to the specific folder?
on a web database in access is it also possible?
 
regret I don't use web databases so cannot advise.

with regards a server based requirement google 'filecopy' to find out more about this function, but in principle you would have code along these lines
Code:
 ....
 ....
 For Each varItem In f.SelectedItems
    strFile = Dir(varItem)
    [B]strFileName=mid(strfile,instrrev(strfile,"\")+1)[/B]
 [B]    filecopy strfile,"C:\storage\" & strFileName[/B]
 [B]    currentdb.execute("INSERT INTO directoryTable (custID,FileName) VALUES(" & me.custID & ", '" & strFileName & "')")[/B]
  
     'strFolder = Left(varItem, Len(varItem) - Len(strFile))
    
     'MsgBox "Folder: " & strFolder & vbCrLf & _
    '"File: " & strFile
    'Me.Text6.Value = strFolder & "\" & strFile
Next

this assumes you want to associate a file with a customer who is identified with CustID
 
forgot to say - the directory C:\Storage needs to already exist
 

Users who are viewing this thread

Back
Top Bottom