插入到从链接表选择中 [英] Insert Into Select From linked table

查看:67
本文介绍了插入到从链接表选择中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行数百次的操作-除了我的代码无法编译之外.使用它作为参考方法将插入到另一个表中的记录插入到表中我想出了以下子程序,该子程序应该清除一个表并从另一个链接表中重新填充它(想法是解放链接表,以便它没有.laccdg文件以其名称命名)

I am trying something that has been done hundreds of times - except my code does not compile. Using this as a reference How to do INSERT into a table records extracted from another table I came up with the following sub, that is supposed to clear a table and refill it from another linked table (The idea is to liberate the linked table so it doesn't have a .laccdg file in its name for long)

Private Sub Form_Open(Cancel As Integer)
    Dim rsDocs As Recordset
    Dim sqlQuery As String

    DoCmd.RunSQL "DELETE * FROM [Docs]"

    sqlQuery = "INSERT INTO [Docs] (Numero, Description, [ID Symix], Groupe, [ID Sami])" & _
                " SELECT [Unité] & "" "" & [Numéro Document] AS Numero, Description, [ID Symix], [Groupe Source], [ID Doc Sami]" & _
                " FROM [Documents]"
        Debug.Print sqlQuery
    Set rsDocs = CurrentDb.OpenRecordset(sqlQuery)
    CurrentDb.Execute sqlQuery
    rsDocs.Close
    Set rsDocs = Nothing
End Sub

在执行行上出现错误. sql语句错误.有人可以看到它变弱的地方吗?在这种情况下,使用""将两个字段连接在一起是否可以接受?

I get an error on the execute line. The sql statement is wrong. Can someone see where it falters? Is the use of "" "" to join two fields together acceptable in this situation?

此外,清除表还会提示您询问我是否确定要执行此操作.将DisplayAlerts设置为False是否会带来负面影响?还是如果我之后立即将其恢复为True,那该无害吗?

Also, clearing the table prompts a message asking if i am sure i want to do this. Will setting DisplayAlerts to False have negative consequences? Or should it be harmless if I put it back to True right after?

推荐答案

用于调试在VBA中设计的查询的一般提示:

A general hint for debugging queries you design in VBA:

  • 执行SQL的Debug.Print(您已经拥有了)
  • 创建一个新查询,关闭添加表"
  • 切换到SQL视图并从调试窗口粘贴您的sql
  • 执行sql或切换到设计视图.

通常,从查询编辑器中收到的错误消息比从VBA中得到的消息更具体.

Usually you will get a more specific error message from the query editor than what you get from VBA.

Access中的DisplayAlerts是:DoCmd.SetWarnings是/否
但这是更好的,可以通过使用DB.Execute来避免它DoCmd.RunSQL的

DisplayAlerts in Access is: DoCmd.SetWarnings True/False
But it is better to avoid it by using DB.Execute instead of DoCmd.RunSQL

这篇关于插入到从链接表选择中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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