473,659 Members | 3,631 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 3276
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 FileSystemObjec t 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,568 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
1670
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 bit of code that did not need classes and I could plug easily into my PHP code. I thought I found one (see bottom of email), however I have since discovered that as it is, this script has the following disadvantages when compared to using...
12
3870
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
0
3771
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 and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
6
8165
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
2104
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 message 4. Upload the attachements to the filesystem 5. Write the path of the attachements to the SQL server record
5
5752
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 know a good place to start looking for some theory on the subject of multi user applications? I know only bits and pieces, like about transactions, but a compendium of possible approches to multi user programming would be very appreciated!
1
1188
by: mkadasi | last post by:
i want to get attachements from outlook and save under windows folder but through programmatically in vb.net
0
2320
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 Systems (MuCoCoS'08) Barcelona, Spain, March 4 - 7, 2008; in conjunction with CISIS'08. <http://www.par.univie.ac.at/~pllana/mucocos08> *********************************************************************** Context
1
9303
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 "PAR.UniqueID" could not be bound. The multi-part identifier "PAR.PAR_Status" could not be bound. The multi-part identifier "Salary.New_Salary" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.