ms access - VBA - Browsing, selecting file and saving file as -


i creating access database forms , reports. in 1 of forms want able go folder selecting file (.pdf, .doc, .xls) , saving in dedicated "attachments" folder.

i know ole objects , attachment functions, both of these saving attachments within database perse. trying stay away since imperative have readily access attachments , make database lighter.

i have been playing in vba

application.filedialog(msofiledialogfilepicker) 

and

application.filedialog(msofiledialogsaveas) 

this have far not working:

option compare database  private sub select_save_click()  call selectfile  end sub   public function selectfile() string      dim fd filedialog  dim file_name string  dim path string  path = "o:\foldername"  set fd = application.filedialog(msofiledialogfilepicker)  fd     .allowmultiselect = false     .title = "please select file save attachment"     if .show = true          file_name = dir(.selecteditems(1))          selectfile = .selecteditems(1)          new_name = path & file_name          .selecteditems.item(1).saveasfile new_name          me.attach_save = new_name       else         exit function     end if      set fd = nothing  end    end function 

consider using filecopy .saveasfile method may not work inside fd object. plus, saveasfile method associated ms outlook vba using email attachments.

also, use dir() on string variable outside fd object , not on variant array .selecteditems(1) inside fd object.

finally, notice add final slash in path string.

dim fd filedialog dim file_name string dim path string  path = "o:\foldername\"  set fd = application.filedialog(msofiledialogfilepicker)  fd     .allowmultiselect = false     .title = "please select file save attachment"     if .show = true         selectfile = .selecteditems(1)     else         exit function             end if end  file_name = dir(selectfile)         filecopy selectfile, path_name & file_name  set fd = nothing 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -