通过访问表单上的按钮将费用记录复制到发票详细信息

问题描述 投票:0回答:2

这是使用发票输入表格将费用记录中的记录添加到发票明细表中,子表单全部通过“inv no”相关联

我正在处理从Exp_Inv_input_Form到sub form = service atlan of main form = atlan inv main的信息

我一直试图使用INSERT INTO没有运气,也无法弄清楚我哪里出错了

    Private Sub btn_copy_Click()

Dim strSql As String
Dim IngID As Long

If Me.Dirty Then
        Me.Dirty = False
    End If

If Me.NewRecord Then
    MsgBox "select the record to duplicate."
Else
    With Me.RecordsetClone
        .AddNew
            !description_date = Me.TransactionDate
            !description = Me.description
            !hours = Me.Quantity
            !Price = Me.SubTotal
            !Total = Me.SubTotal
        .Update

        .Bookmark = .LastModified
        IngID = !inv_no

        If Me.RecordsetClone.RecordCount > 0 Then
            strSql = "insert into [service atlan subform]([inv no], [description date], description, hours, Price, Billed )" _
                "SELECT " & lngID & " As NewID, description, Quantity, Total, from_exp " & _
                "FROM [service atlan] WHERE inv no = " & Me.inv_no & ";"
        DBEngine(0)(0).Execute strSql, dbFailOnError
    Else
        MsgBox "Main record duplicated, but there were no related records."
    End If
Exit_Handler:
    Exit Sub

Err_Handler:
    MsgBox "Error " & Err.Number & " - " & Err.description, , "cmdDupe_Click"
    Resume Exit_Handler
End Sub

现在它告诉我我的strSql有问题我需要在两个表中命名colums相同,因为我被引导相信它们放置它们的序列

提前致谢

ms-access access-vba
2个回答
0
投票

你的sql语句几乎没有问题。如果列名称中有空格,请用[]括起来。

insert语句中的列数也与select语句不匹配

,声明中的表名后面还有Insert


0
投票

我一直在搞乱SQL改变了表结构,并取得了成功我的bigest问题是Select语句的结构

"INSERT INTO [Transaction List] ([TransactionDate], [Inv No], [Division], [MomsrevLookup], [Total], [Catagory]) " & _
        "Select """ & Me.[TransactionDate].Value & """, """ & Me.[inv no].Value & """,""" & Me.[Division].Value & """,""" & Me.revmoms.Value & """,""" & Me.[Inv_Total].Value & """,""" & Me.[Catagory].Value & """"

它现在正在处理表单中的选定行并将它们粘贴到另一个表上的新记录中

© www.soinside.com 2019 - 2024. All rights reserved.