2017-10-19 11 views
-2

こんにちは私はこれについて何かを見つけることができません。誰かが正しい方向に私を向けることができれば素晴らしいでしょう。Microsoft Access - 画像をフォルダディレクトリに基づいてデータベースに自動的にリンクさせます+ firstname lastname

私は4000人のジムメンバーを持つアクセスデータベースを持っています。 指定したディレクトリからリンクしてプロフィール写真を追加したいと思います。 私は例えば、私はそれが自動的にディレクトリに検索し、同じ を持っています絵とファーストネーム+ラストネーム+メンバーのDOBを合わせたい手動で4000枚の写真

をリンクしたくない:bobjones05121989

あなたの助けを前にありがとう。

+0

あまりにも広い質問、追加情報が必要です。あなたはfirstname + last name + DOBをどこから取得しますか?私が推測する形式ですか?画像パスをデータベースに保存するか、フォームが読み込まれるとすぐに表示するのか? (そうだとすれば)。どうか明らかにしてください。 –

+0

あなたの返事をありがとう。はい、データはフォームからのものです。私はリンクを表示するだけです。データベース内に格納しない –

答えて

0

A Access 2007以降をお使いですか?イメージコントロールのControlSourceプロパティを使用します。イメージが存在しない場合は

="C:\somepath\" & [FirstName] & [LastName] & Format([DOB], "ddmmyyyy") & ".jpg"

Imageコントロールが空白になります:式は次のように、ファイルパスを構築することができます。

+0

パーフェクトありがとう –

0

フォームが読み込まれるときにこれを試してください。

フィールド名をデータベースの実際の名前に変更する必要があります。

あなたが何かをダウンロード(すでにファイルを持っている)が、ちょうど画像のパスを返しIDよりも、ありません(ここでのように)他のいくつかのフィールド(複数可)からリンクするUrlContent機能 を変更することができ
Private Sub Form_Load() 
    Dim imagepath As String 
    With Me 
     imagepath = "Drive:\" & LCase(![FirstName]) & LCase(![LastName]) & Format(![DOB], "ddmmyyyy") & ".jpg" 
    End With 

    If Len(Dir(imagepath)) > 0 Then 
     Me.ImageControl.Picture = imagepath 
    End If 
End Sub 
+0

Access 2007以降を使用している場合は、ImageコントロールのControlSourceプロパティをファイルパスを構築する式で設定できます。 VBAは必要ありません。 – June7

0

' Download (picture) file from a URL of a hyperlink field to a 
' (temporary) folder, and return the full path to the downloaded file. 
' 
' This can be used as the control source for a bound picture control. 
' If no Folder is specified, the user's IE cache folder is used. 
' 
' Typical usage in the RecordSource for a form or report where Id is 
' the unique ID and Url is the hyperlink field holding the URL to 
' the picture file to be displayed: 
' 
'   - to a cached file where parameter Id is not used: 
' 
'   Select *, UrlContent(0, [Url]) As Path From SomeTable; 
' 
'   - or, where Id is used to create the local file name: 
' 
'   Select *, UrlContent([Id], [Url], "d:\somefolder") As Path From SomeTable; 
' 
' Then, set ControlSource of the bound picture control to: Path 
' 
' 2017-05-28. Gustav Brock, Cactus Data ApS, CPH. 
' 
Public Function UrlContent(_ 
    ByVal Id As Long, _ 
    ByVal Url As String, _ 
    Optional ByVal Folder As String) _ 
    As Variant 

    Const NoError   As Long = 0 
    Const Dot       As String = "." 
    Const BackSlash As String = "\" 
    
    Dim Address     As String 
    Dim Ext         As String 
    Dim Path        As String 
    Dim Result      As String 
    
    ' Strip leading and trailing octothorpes from URL string. 
    Address = HyperlinkPart(Url, acAddress) 
    ' If Address is a zero-length string, Url was not wrapped in octothorpes. 
    If Address = "" Then 
        ' Use Url as is. 
        Address = Url 
    End If 
    
    If Folder = "" Then 
        ' Import to IE cache. 
        Result = DownloadCacheFile(Address) 
    Else 
        If Right(Folder, 1) <> BackSlash Then 
            ' Append a backslash. 
            Folder = Folder & BackSlash 
        End If 
    
        ' Retrieve extension of file name. 
        Ext = StrReverse(Split(StrReverse(Address), Dot)(0)) 
        ' Build full path for downloaded file. 
        Path = Folder & CStr(Id) & Dot & Ext 
        
        If DownloadFile(Address, Path) = NoError Then 
            Result = Path 
        End If 
    End If 
    
    UrlContent = Result 
    
End Function 

記事と完全なデモはここで見つけることができます:

Show pictures directly from URLs in Access forms and reports

+0

写真はすでにインターネット上ではなくディレクトリにあるので、理解している限り、これは当てはまりません。だから、HTTPダウンロードを利用することは必要ありません。 –

+0

答えは、ファイルパスを返すだけで、ダウンロードしないようにコードを修正すると言います。 – June7

+0

@ErikvonAsmuth:True。私はあなたが主要な文章を逃したと信じています:_機能を変更する.. ..何もダウンロードしないでください。ただ画像のパスを返します。要するに、ダウンロード機能を省くこと。私たちは写真やネーミングスタイルについて何も知らないので、解決するには質問者が解決する必要があります。 – Gustav

関連する問題