2010-04-29 40 views
1

此代碼來自我一直在努力的Access 2007項目。 實際平均一部分是我應該把類似「僅更新當前表單」訪問2007文件選取器,用相同的選項替換所有行

DoCmd.RunSQL "Update Korut Set [PikkuKuva]=('" & varFile & "') ;" 

可能有人請幫助我?'如果我現在使用它,它更新所有使用相同的表的一部分文件摘取。

繼承人整個代碼。

' This requires a reference to the Microsoft Office 11.0 Object Library. 

    Dim fDialog As Office.FileDialog 
    Dim varFile As Variant 
    Dim filePath As String 


    ' Set up the File dialog box. 
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker) 
    With fDialog 
     ' Allow the user to make multiple selections in the dialog box. 
     .AllowMultiSelect = False 

     ' Set the title of the dialog box. 
     .Title = "Valitse Tiedosto" 

     ' Clear out the current filters, and then add your own. 
     .Filters.Clear 
     .Filters.Add "All Files", "*.*" 

     ' user picked at least one file. If the .Show method returns 
     ' False, the user clicked Cancel. 
     If .Show = True Then 
     ' Loop through each file that is selected and then add it to the list box. 
     For Each varFile In .SelectedItems 
      DoCmd.SetWarnings True 
      DoCmd.RunSQL "Update Korut Set [PikkuKuva]=('" & varFile & "') ;" 
     Next 
     Else 
     MsgBox "You clicked Cancel in the file dialog box." 
     End If 
    End With 
+0

這是不倫不類關於你的問題,但如果你改變了「昏暗fDialog作爲Office.FileDialog」到「點心fDialog爲對象」,代之以「msoFileDialogFilePic克爾「與」3「,你不需要參考。 – 2010-04-30 00:22:39

回答

2

這是猜測的東西是,你正在運行的代碼,你不說,但作爲一般規則,你需要的東西線:

DoCmd.RunSQL "Update Korut Set [PikkuKuva]=('" & varFile & "') WHERE ID=" 
       & Me.ANumericID 

如果唯一值爲您的形式是文字,則需要使用引號:

DoCmd.RunSQL "Update Korut Set [PikkuKuva]=('" & varFile & "') WHERE ID='" 
       & Me.ATextIDWithNoSingleQuotes & "'" 
+0

要更明確地說明@Remou說的是什麼:你的UPDATE語句沒有WHERE子句,所以它會更新所有的行。您需要一個WHERE子句,將每個更新限制爲您想要存儲文件名的單行或一組行。 – 2010-04-30 00:24:43

+0

感謝這兩者,讓它能夠從另一個表中檢查。 現在我正在努力如何將自動編號ID複製到輔助字段。 我目前正在嘗試在form_load上「db.OpenRecordset」,但我被如何複製x-> y誤導了。 – HoxDef 2010-05-05 07:43:44

+0

發表另一個問題,它會很快拾起。 – Fionnuala 2010-05-05 07:50:00