Access 2007 文件选择器,用相同的选择替换所有行

发布于 2024-08-31 09:07:55 字数 1333 浏览 1 评论 0原文

这段代码来自我一直在努力解决的 Access 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

This code is from an Access 2007 project I've been struggling with.
The actual mean part is the part where I should put something like "update only current form"

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

Could someone please help me with this?` If I use it now, it updates all the tables with the same file picked.

Heres the whole code.

  ' 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-09-07 09:07:55

这是猜测工作,因为您没有说明在哪里运行代码,但作为一般规则,您需要以下内容:

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

如果表单的唯一值是文本,则需要引号:

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

This is something of guess work as you do not say where you are running the code, but as a general rule, you need something on the lines of:

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

If the unique value for your form is text, you will need quotation marks:

 DoCmd.RunSQL "Update Korut Set [PikkuKuva]=('" & varFile & "') WHERE ID='" 
               & Me.ATextIDWithNoSingleQuotes & "'"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文