how to browse files and store them to database (1 Viewer)

mana

Registered User.
Local time
Today, 05:30
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:30
Joined
Feb 19, 2013
Messages
14,170
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
 

mana

Registered User.
Local time
Today, 05:30
Joined
Nov 4, 2014
Messages
265
hi,

thank you
i am using access 2010.
can you guide me please more
i couldn't find an appropriate code
thanks
 

mana

Registered User.
Local time
Today, 05:30
Joined
Nov 4, 2014
Messages
265
how can i store the files to the specific folder?
on a web database in access is it also possible?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:30
Joined
Feb 19, 2013
Messages
14,170
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 13:30
Joined
Feb 19, 2013
Messages
14,170
forgot to say - the directory C:\Storage needs to already exist
 

Users who are viewing this thread

Top Bottom