Avatar billede per2edb Praktikant
18. maj 2012 - 11:26 Der er 35 kommentarer og
1 løsning

trække filer fra outlook til Access

Hi

Jeg har access 2007
Kan i hjælpe:

Jeg ønsker at kunne trække filer fra outlook (Excel,Doc)
over i min access DB hvor de placeres i en mappe så de kan
nås med en link.
Jeg har det i dag så jeg kan flytte dokumenterne fra outlook til en mappe og uplode til Access men jeg ønsker at trække direkte fra outlook til Access

Har i koderne hertil?
Avatar billede terry Ekspert
18. maj 2012 - 17:23 #1
can you be moe specific as to what you want?

You say "...over i min access DB hvor de placeres i en mappe så de kan nås med en link. .."

but then you say that you already can most of what you want to do "jeg kan flytte dokumenterne fra outlook til en mappe."


so iof thats the case all you need to do is save the path\filename of the documents and then using shellexecuteyou can open the files.

and I'm sure you can find loads of examples of using shellexecute in this forum
Avatar billede terry Ekspert
18. maj 2012 - 17:27 #2
Avatar billede per2edb Praktikant
19. maj 2012 - 12:25 #3
Jeg prøver igen:
I outlook har jeg en vedhæftet fil.
Dem ønsker jeg trukket over i Access i en tekstbox.
Her skal linket til filen gemmes i Access
Selve filen skal gemmes i en mappe på disken.
Avatar billede terry Ekspert
19. maj 2012 - 14:55 #4
can you do this?
"Jeg har det i dag så jeg kan flytte dokumenterne fra outlook til en mappe"?
Avatar billede per2edb Praktikant
19. maj 2012 - 17:26 #5
Jeg prøver igen:
Ja jeg kan selvfølgelig flytte filer til en mappe det er ikke det jeg spørger om.
Jeg ønsker at trække outlooks vedhæftede filer over til en tekstbox i ACCESS 2007. Her skal linket til filen gemmes i Access
og selve filen skal saves på disken.
Avatar billede terry Ekspert
19. maj 2012 - 18:10 #6
per2edb I'm trying to find out what you can and what you cant do already, because I dont intend waisting my time in telling you something you already know.


If you can already save an attached file to a folder then you must already have most of the code for what you want to do.

If you can do that then I assume you have the path and filename which you now can save in a textbox.

And if we dont understand each other then I think you will have to wait until someone else comes by.
Avatar billede per2edb Praktikant
20. maj 2012 - 11:54 #7
Hej
If you can already save an attached file => nej den er ikke savet i en folder på dette tidspunkt.
1) filen trækkes over fra Outlook til access.
2) så spørges der om den skal saves- samt hvor.
3) der svares ja og stien angives, hvorefter den saves på disken
4) Linket til filen saves i access
5) efterfølgende kan et klik på dette link vise filen

Denne metode findes i mange professionelle programmer - benævnt - "træk og slip" MS bruger det også selv.
Avatar billede terry Ekspert
20. maj 2012 - 14:43 #8
OK, that helps but just need to clear up 1)"filen trækkes over fra Outlook til access"

hows that done? You must obviously be able to get hold of the file(s) from outlook
Avatar billede per2edb Praktikant
20. maj 2012 - 14:59 #9
klikker med musen på filen i outlook og holder den nede medens jeg trækker ocer til ACCESS og slipper over tekstboxen
Avatar billede terry Ekspert
20. maj 2012 - 15:45 #10
well the biggets problem here is actually getting hold of the attachmenst in Oulook.

You need to break the task into a numbver of smaller tasks and then put them all together when each work.

Start by just getting the save attachments working first tthen take it from there.

Here an example which I havent tested, see if you can get taht working first.
http://www.dbforums.com/microsoft-access/985662-ms-outlook-attachments-access.html
Avatar billede per2edb Praktikant
20. maj 2012 - 17:11 #11
Tak. Jeg prøver først dette
Avatar billede per2edb Praktikant
20. maj 2012 - 18:15 #12
Det virker desværre ikke!!!!
Jeg har lagt nedenfor viste koder i et VBA modul i outlook
Herudover oprettet C:\new email
Der vises fejl i:

Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFo lderInbox)
og
If UCase(Right(myFolder.Items(A).Attachments(b).Displ ayName, 3)) = "XLS" Then
----- Outlook -----
Private Sub Application_NewMail()

Dim myFolder As Outlook.MAPIFolder

Set myOlApp = CreateObject("Outlook.application")
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFo lderInbox)
Set myitem = myOlApp.CreateItem(olMailItem)

For A = 1 To myFolder.Items.Count
If myFolder.Items(A).UnRead = True Then
If myFolder.Items(A).Attachments.Count <> 0 Then
For b = 1 To myFolder.Items(A).Attachments.Count
If UCase(Right(myFolder.Items(A).Attachments(b).Displ ayName, 3)) = "XLS" Then

the_filename = "C:\new email\recd " & Format(Now(), "dd-mmm-yyyy") & " " & myFolder.Items(A).Attachments(b).DisplayName
myFolder.Items(A).Attachments(b).SaveAsFile the_filename

End If
Next
End If
End If
Next
End Sub
Avatar billede terry Ekspert
20. maj 2012 - 19:27 #13
Jeg har lagt nedenfor viste koder i et VBA modul i outlook

??
Now you have confused me!

The code is supposed to be in access which gets the attachments from Outlook
Avatar billede per2edb Praktikant
20. maj 2012 - 22:17 #14
Ohhhh?
Det prøver jeg
Avatar billede per2edb Praktikant
21. maj 2012 - 11:16 #15
Det virker heller ikke?
Der vises fejl i:

Dim myFolder As Outlook.MAPIFolder

Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFo lderInbox)

og

If UCase(Right(myFolder.Items(A).Attachments(b).Displ ayName, 3)) = "XLS" Then

----- Access -----

Private Sub Tilbud_Leverandør_Doc_2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim myFolder As Outlook.MAPIFolder

Set myOlApp = CreateObject("Outlook.application")
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFo lderInbox)
Set myitem = myOlApp.CreateItem(olMailItem)

For a = 1 To myFolder.Items.Count
If myFolder.Items(a).UnRead = True Then
If myFolder.Items(a).Attachments.Count <> 0 Then
For b = 1 To myFolder.Items(a).Attachments.Count
If UCase(Right(myFolder.Items(A).Attachments(b).Displ ayName, 3)) = "XLS" Then

the_filename = "C:\new email\recd " & Format(Now(), "dd-mmm-yyyy") & " " & myFolder.Items(a).Attachments(b).DisplayName
myFolder.Items(a).Attachments(b).SaveAsFile the_filename

End If
Next
End If
End If
Next

End Sub
Avatar billede terry Ekspert
21. maj 2012 - 20:50 #16
you will need a reference to Outlook.
Tools+References menu
Avatar billede per2edb Praktikant
21. maj 2012 - 23:42 #17
Kan du hjælpe med koderne til det
Avatar billede terry Ekspert
22. maj 2012 - 18:33 #18
This works. If you cant get it to work than I cant help you.

Curently the code only looks for .docx files. The destination folder must exist, and dont forget the refernce


im myFolder As Outlook.MAPIFolder
Dim myOlApp As Outlook.Application
Dim myItem  As Outlook.MailItem
Dim a As Integer
Dim b As Integer
Dim the_filename As String


Set myOlApp = CreateObject("Outlook.application")
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set myItem = myOlApp.CreateItem(olMailItem)


    For a = 1 To myFolder.Items.Count
        If myFolder.Items(a).UnRead = True Then
            If myFolder.Items(a).Attachments.Count <> 0 Then
                For b = 1 To myFolder.Items(a).Attachments.Count
                    If UCase(Right(myFolder.Items(a).Attachments(b).DisplayName, 4)) = "docx" Then
                        the_filename = "C:\new email\recd " & Format(Now(), "dd-mmm-yyyy") & " " & myFolder.Items(a).Attachments(b).DisplayName
                        myFolder.Items(a).Attachments(b).SaveAsFile the_filename
   
                    End If
                Next
            End If
        End If
    Next
Avatar billede per2edb Praktikant
22. maj 2012 - 21:20 #19
Jeg er ked af det men:
Der er fejl i første linie

im myFolder As Outlook.MAPIFolder < mælder fejl her
Avatar billede terry Ekspert
22. maj 2012 - 21:38 #20
have you out the code in a sub/function?
and have you set that refercne I mentioned?

I have tested the code and it works
Avatar billede per2edb Praktikant
22. maj 2012 - 23:26 #21
Ja det er lagt i:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
.
.
End sub

Jeg ved ikke hvad refercne er "Suk"
Avatar billede terry Ekspert
23. maj 2012 - 18:58 #22
In code view you should see a menu tool and in that a menu references. Then find outlook in the list ...
Avatar billede per2edb Praktikant
23. maj 2012 - 20:47 #23
Så vidt jeg kan se er der ingen.
Det er da i access jeg skal finde den - ikke?
Avatar billede terry Ekspert
23. maj 2012 - 20:56 #24
yes. If Outlok is installed on your pc then I would expect theer to be a an entry for outlook

Microsoft Outlook some number Object Library

can you find the references menu?
Avatar billede per2edb Praktikant
24. maj 2012 - 12:25 #25
Yes i have Outlook office 2007
But in access is no Outlook referance
Avatar billede terry Ekspert
24. maj 2012 - 19:16 #26
well until you can solve that problem you wont get thsi code to work
Avatar billede per2edb Praktikant
25. maj 2012 - 11:57 #27
Så fandt jed dem:

Hvad skal jeg vælge?:

acCmdAddFromOutlook
ImportAttachOutlook
Save as Outlook Contact

Hvad skal jeg så skrive i koderne?
Avatar billede terry Ekspert
28. maj 2012 - 16:49 #28
You shouldnt choose any of them. I think your in the wrong menu!

As far as I can make out your in the import menu.. you need the TOOLS+REFERENCES menu which you can find while you are in code view.

The menu look ssomething like this ..

http://www.bluemoosetech.com/microsoft-access-vba.php?jid=12&title=VBA%20Tools%20-%20References%20in%20Microsoft%20Access
Avatar billede per2edb Praktikant
03. juli 2012 - 15:14 #29
Jeg fik det aldrig til at virke men tager det op igen senere
Avatar billede terry Ekspert
03. juli 2012 - 19:23 #30
shouldnt we close the question then?
Avatar billede per2edb Praktikant
04. juli 2012 - 16:33 #31
Jeg prøver igen på Søndag
Avatar billede per2edb Praktikant
09. juli 2012 - 14:42 #32
Hej Igen

Jeg Fandt:
Microsoft office Outlook view Control
og
Microsoft Outlook 12 object libery

Begge er nu vedhæftet men der kommer fejl i linie 1:
Im MyFolder as.....




Private Sub Tilbud_Leverandør_Doc_2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

im myFolder As Outlook.MAPIFolder
Dim myOlApp As Outlook.Application
Dim myItem  As Outlook.MailItem
Dim a As Integer
Dim b As Integer
Dim the_filename As String

Set myOlApp = CreateObject("Outlook.application")
Set myFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set myItem = myOlApp.CreateItem(olMailItem)
    For a = 1 To myFolder.Items.Count
        If myFolder.Items(a).UnRead = True Then
            If myFolder.Items(a).Attachments.Count <> 0 Then
                For b = 1 To myFolder.Items(a).Attachments.Count
                    If UCase(Right(myFolder.Items(a).Attachments(b).DisplayName, 4)) = "pdf" Then
                        the_filename = "C:\new email\recd " & Format(Now(), "dd-mmm-yyyy") & " " & myFolder.Items(a).Attachments(b).DisplayName
                        myFolder.Items(a).Attachments(b).SaveAsFile the_filename
   
                    End If
                Next
            End If
        End If
    Next

End Sub
Avatar billede terry Ekspert
09. juli 2012 - 18:57 #33
im myFolder As Outlook.MAPIFolder

im should be DIM
Avatar billede per2edb Praktikant
09. juli 2012 - 22:25 #34
Nu er fejlen væk men intet sker?
Jeg trækker en pdf fil over fra outlook til access.
Her vises et lille + Så slipper jeg musen - men intet sker?
Avatar billede terry Ekspert
10. juli 2012 - 18:26 #35
Jeg trækker en pdf fil over fra outlook til access.

You shouldnt have to do that, the code should do it for you.

This question is taking a long time to answer! I cant teach you the basics...

You will need to through the code to see what is happening and it doesnt help that I can get it to work on my PC because its you who needs to get it to work on your PC.

If you cant manage to debug the code then I think you will have to get help elsewhere :o(
Avatar billede per2edb Praktikant
15. juli 2012 - 17:33 #36
Det er en email med en attached pdf fil jeg trækker over til access.

Debug viser:
myOlApp =  "outlook"
myFolder = "indbakke"
myItem = ""  <= Hvorfor er den Tom ?
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester