17. december 2008 - 14:17Der er
24 kommentarer og 1 løsning
Hvordan indsætter jeg billede i rapport vha. url?
Jeg prøver at sætte et billede ind ved hjælp af URL. Jeg har gemt værdien i en tabel (ImageURL), men kan ikke finde ud af at sætte billedet ind. Ultimativt vil jeg helst kunne sætte et visio diagram ind, men ved ikke hvordan jeg skal klare den heller...
I dont think you can embed a picture from a URL in a report if that is what your hoping to do. And I see no point at all having a URL in a report, once its printed you cant open the file from the report.
So please try explaining what it is exactly you want to do.
Ok - jeg præver lige at uddybe: Jeg har en liste i Sharepoint, som blandt andet indeholder referencer til billedet som skal med i rapporten. Der er et specifik billede til hver post, angivet i en kollen med navnet ImageURL. Eftersom billederne ligger på sharepointserveren kan jeg ikke angive billedets absoluttet sti, men er nødt til at angive billedets placering vha. en URL. Eksemplet med billedet i artiklen nævnt ovenfor virker fint, men kun på billeder placeret på lokal maskine.
Resultatet skulle gerne blive en rapport som til hver post henter det billede der refereres til i kolonnen, og derfor skal url'en kun bruges til at hente billedet ind - ikke klikkes på eller andet.
Håber det kaster lidt lyst på dagen. Jeg tænker at det evt. kan gøres ved at hente billedet ind som file object og derefter behandle det videre?
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer) Me.ImageHolder.Picture = "" Dim URL As String If Me.DiagramURL.Value <> "" Then URL = Me.DiagramURL.Value End If MsgBox ("Header") If URL <> "" Then MsgBox (URL)
Dim surl, slocal, oxmlhttp, ostream
surl = URL slocal = "c:\temp\cad.gif"
On Error Resume Next Set oxmlhttp = CreateObject("msxml2.xmlhttp") If Err.Number <> 0 Then wscript.Echo "msxml2.xmlhttp not installed. Operation aborted." wscript.Quit (1) End If With oxmlhttp .Open "get", surl, False .send End With If Err.Number <> 0 Then wscript.Echo "Resource unavailable for varied reasons. Operation aborted." Set oxmlhttp = Nothing: wscript.Quit (2) End If
Set ostream = CreateObject("adodb.stream") With ostream .Type = 1 'binary .mode = 3 'read-write .Open .write oxmlhttp.responsebody .SaveToFile slocal, 2 'save-create-overwrite .Close End With If Err.Number <> 0 Then wscript.Echo "You need ado2.5 up. Operation aborted" Else wscript.Echo "Done!" & vbCrLf & "Source : " & surl & vbCrLf & "Local : " & slocal End If On Error GoTo 0 Set ostream = Nothing: Set oxmlhttp = Nothing
Me.ImageHolder.Picture = "c:\temp\cad.gif"
Else MsgBox ("No image") End If
End Sub
Mangler at teste det på et større datasæt, men tror at det virker. Der skal laves et tjek på om mappen 'temp' findes og hvis ikke skal den oprettes, men ellers tror jeg der er der. Der skal sikkert også ryddes lidt op i koden inden den kører... Smmider den endelige kode op når jeg er done. Point?
Terry: Yes please. Can you put the code...? The approach is working fine, put I'm trying to skip the process of using an image and importing visio files instead. (see http://www.eksperten.dk/spm/857041)
I'm not at all sure if Visio files can be shown in an Acess rport but I'll have a play around later. I assume you still need to download the file still?
Put this in a module. It will need modifying depending on how you want to use it, maybe call it with two parameters, URL + SavePath. You should maybe also delete the fiel if it already exist, and ensure that detination path (folder) exists too, or create.
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownLoadFile()
Dim retVal As Long 'our return value Dim theUrl As String 'the url you want to download Dim savePath As String 'where you want to save the url
theUrl = "Put your URL to download here" savePath = "And Save path here"
Hi Terry. I'm back... I can't get your code to work, it seams that nothing happens when I run it. I short: I need to be able to download a file based on the URL. I also need to be able to specify where to save the file.
Shouldn't i be able to do that from the code above?
Yes the code given 19/12-2008 18:16:21 should download a file form the URL and save it. If its possible to send me a URL which I can use to test then I can see if I can get it to work with your URL.
Hi Terry. I have used the code mentioned in top of this thread. Is seams to work fine, so i'll leave at this. I have solved the other problem, regarding reports and visio. I create a word document from access using vbscript, and then place content from the tables in it. It works great now.
Great. Good idea using Word. Although Access reports are good, using Word for reports etc. gives you more control, although it normally take more time to make.
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.