Access 2007文件选择器,用相同的选择替换所有行 [英] Access 2007 file picker, replaces all rows with the same choice

查看:98
本文介绍了Access 2007文件选择器,用相同的选择替换所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码来自我一直在努力的Access 2007项目. 实际的均值部分是我应该输入仅更新当前表单"之类的部分

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.

这里有整个代码.

  ' 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

推荐答案

这是一种猜测工作,因为您没有说出在哪里运行代码,但是作为一般规则,您需要以下代码: /p>

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

如果表单的唯一值是text,则需要用引号引起来:

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 & "'"

这篇关于Access 2007文件选择器,用相同的选择替换所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆