473,505 Members | 14,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multi attachements

3 New Member
I'm new to VBA.
I'm trying to figure it out how to make Access, upon click of a button, open a load-from-file window to upload 8 files.
I have some particular thing about it.
I need it to rename to the autonumber of the form, auto upload the 8 and export to a predetermined location.

The code I have so far is.
Expand|Select|Wrap|Line Numbers
  1. 'FILE DIALOG OPENS UPLOAD PANEL
  2. Private Sub Comando715_Click()
  3. Call Selectfile
  4. End Sub
  5. 'FUNÇÃO CAIXA DE SELEÇÃO
  6. Public Function Selectfile() As String
  7. Dim Fd As FileDialog
  8. Dim Filtro As FileDialogFilters
  9. Set Fd = Application.FileDialog(msoFileDialogOpen)
  10. With Fd
  11.     'FILTRO DE IMAGENS
  12.     Set Filtro = .Filters
  13.     With Filtro
  14.     .Clear
  15.     .Add "Imagens", "*.jpeg;*.jpg"
  16.     End With
  17.     'NÃO PERMITIR MULTI-SELEÇÃO
  18.     .AllowMultiSelect = True
  19.     'DEFINE O NOME DA CAIXA DE SELEÇÃO
  20.     .Title = " Por favor introduza as fotos da peça"
  21.     If .Show = True Then
  22.     'CODIGO DE COLOCAÇÃO DE ANEXO EM FORMULÁRIO
  23.             Selectfile = .SelectedItems(1)
  24.             Me.Anexo412.DefaultPicture = Selectfile
  25.     Else
  26.     MsgBox "Clicou no botão cancelar ao escolher imagem."
  27.         Exit Function
  28.     End If
  29.     Set Fd = Nothing
  30. End With
  31. End Function
Someone has some ideas how to do it?
Jul 2 '15 #1
6 3265
frederiko
3 New Member
Well i made some progress.
Ive constructed this code and donloaded the dao360.dll and now another part of the code doesnt seams to work.

The code i have so far is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveToAttachmentField()
  2.     Dim rsRecord As DAO.Recordset
  3.     Dim rsAttach As DAO.Recordset2
  4.     Dim fldAttach As DAO.Field2
  5.     Dim dlgOpen As Office.FileDialog
  6.     Dim selFile As Variant
  7.  
  8.     Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
  9.     With dlgOpen
  10.         .Title = "Selecionar fotos para adicionar ao registo"
  11.         .ButtonName = "Selecione ficheiro(s)"
  12.         .AllowMultiSelect = True
  13.         .InitialFileName = "Path:\to\default\folder"
  14.         .Filters.Add "Imagens", "*.jpeg;*.jpg", 1
  15.         If .Show <> 0 Then
  16.         Me.Dirty = False
  17.     Set rsRecord = Me.RecordsetClone
  18.         With rsRecord
  19.         .Bookmark = Me.Bookmark
  20.         .Edit
  21.         Set rsAttach = .Fields("Anexo412").Value
  22.             With rsAttach
  23.             For Each selFile In dlgOpen.SelectedItems
  24.                 .AddNew
  25.                 .Fields("FileData").LoadFromFile selFile
  26.                 .Update
  27.             Next
  28.                 End With
  29.                 .Update
  30.             End With
  31.         End If
  32.     End With
  33.  
  34.     rsRecord.Close
  35.     Set rsRecord = Nothing
  36.     Set rsAttach = Nothing
  37.     Set dlgOpen = Nothing
  38. End Sub
In particular the error is in line
Expand|Select|Wrap|Line Numbers
  1. Dim rsAttach As DAO.Recordset2
and the error says "Defined type by user not defined"

Im making some progress but without help is becoming very dificult
Jul 7 '15 #2
jforbes
1,107 Recognized Expert Top Contributor
I would not recommend inserting files into your Database. I would highly, highly recommend against it. The reasons are that if it doesn't break your database, it will not run very well. I played around with it years ago and it adds a ridiculous amount of overhead to the application.

What I would recommend is to save the files off in a directory and then save the Filename and Path into the database. Since it looks like you are primarily using Images, you can use the Image Control and bind it to the Filename and Path of Image stored on disk and the Image Control will show the Image for you.
Jul 7 '15 #3
zmbd
5,501 Recognized Expert Moderator Expert
A very recent thread... covering the topic Jforbes has mentioned.
http://bytes.com/topic/access/answer...nt-attachments
Jul 8 '15 #4
frederiko
3 New Member
Ok i get it. Im thinking have 80.000 auto parts with 3/4 photos per item and i think that access will become very slow.
Basicly i need the VBA to copy the photos from memory card, move to the external hard drive, then rename with number of the part folowed by _1 for photo 1 _2 for photo2. Im giving an example
ID10200_1; ID10200_2 do you get it?
Now i can add an attachment but i didnt figure out how to do those actions prior adding the path to the file.
Thanks for you support.

The code i have fully working so far is:
Expand|Select|Wrap|Line Numbers
  1. 'FILE DIALOG OPENS UPLOAD PANEL
  2. Private Sub Comando715_Click()
  3. Call SaveToAttachmentField
  4. End Sub
  5. Private Sub SaveToAttachmentField()
  6.     Dim rsRecord As DAO.Recordset
  7.     Dim rsAttach As DAO.Recordset2
  8.     Dim fldAttach As DAO.Field2
  9.     Dim dlgOpen As Office.FileDialog
  10.     Dim selFile As Variant
  11.  
  12.     Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
  13.     With dlgOpen
  14.         .Title = "Selecionar fotos para adicionar ao registo"
  15.         .ButtonName = "Selecione ficheiro(s)"
  16.         .AllowMultiSelect = True
  17.         .InitialFileName = "Path:\to\default\folder"
  18.         .Filters.Add "Imagens", "*.jpeg;*.jpg", 1
  19.         If .Show <> 0 Then
  20.         Me.Dirty = False
  21.     Set rsRecord = Me.RecordsetClone
  22.         With rsRecord
  23.         .Bookmark = Me.Bookmark
  24.         .Edit
  25.             Set rsAttach = .Fields("FOTO1").Value
  26.             With rsAttach
  27.             For Each selFile In dlgOpen.SelectedItems
  28.                 .AddNew
  29.                 .Fields("FileData").LoadFromFile selFile
  30.                 .Update
  31.             Next
  32.                 End With
  33.                 .Update
  34.             End With
  35.         End If
  36.     End With
  37.     On Error Resume Next
  38.     rsRecord.Close
  39.     Set rsRecord = Nothing
  40.     Set rsAttach = Nothing
  41.     Set dlgOpen = Nothing
  42. End Sub
  43.  
Jul 9 '15 #5
zmbd
5,501 Recognized Expert Moderator Expert
80K+ Images....
YIKES
As you surmised... not really a good thing for Access.
If you were to attempt to add them to the Access database, especially if these are large image files I would advise using a multiple backend approach...
Frontend for your interface
Backend one for data
Backend two (three, four, etc... (figure around (roughly) 400 images at 4MB per file for larger images - your mileage may vary)) for your images and that's only a workaround...

A better approach if you wanted them in the database is to move to either MySQL or MariaDB - both open source (amongst many others - I see more MySQL here than others and MariaDB is almost a drop-in replacement for MySQL); or to one of the commercial RDMS such as SQLServer, Oracle, etc...

To the heart of your last post:

I have not reviewed your code; however, the following should point you in the correct direction:

+ You can do the move and rename in one shot (just because you can, doesn't mean you should):
Name Statement

Instead, the way I do this, because there have been issues with security/sharing on my network:

First:
FileExists() and FolderExists() functions
In the source folder

Next:
FileCopy Statement

Verify:
FileExists() and FolderExists() functions
In the destination folder
If found then make the entry into the recordset holding the paths to your image files.

Finally (Optional):
Kill Statement
the original file.

Verify the delete (Optional)
FileExists() and FolderExists() functions
In the source folder

++ You can use the FileSystemObject Object and related methods; however, for simple tasks such as this, I don't see any reason to increase the application overhead.
Jul 9 '15 #6
NeoPa
32,557 Recognized Expert Moderator MVP
Just posting to indicate to OP that I've seen the thread (He mistakenly PMed me the same question).

Little need for me to add anything at this stage as you guys are already doing a great job :-)
Jul 10 '15 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1664
by: Dave Smithz | last post by:
Hi there, Previously in my PHP code I was using Sendmail to send out emails to people in the MySQL DB. The requirement cam along to be able to send attachments and so I dug around for an easy...
12
3842
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
3746
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
8137
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
1
2085
by: hanan_cohen | last post by:
Shalom, I am looking for a system that will: 1. Read a message from a POP3 mailbox 2. Parse the message into its parts 3. Create a record in an SQL server table with selected fields of the...
5
5703
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
1
1176
by: mkadasi | last post by:
i want to get attachements from outlook and save under windows folder but through programmatically in vb.net
0
2296
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
9284
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.