这实际上如何更新表格?

时间:2010-01-27 20:57:25

标签: ms-access ms-access-2007

警告:我对Access编码很新。 我习惯于.NET和PHP

我刚刚将Access 95程序转换为Access 2007,我现在正在努力进行一些更新。

我有一个更新数据库中的表的表单,但我找不到附加的查询或其实际执行SQL语句的任何地方。请帮忙。谢谢你。

这是一张表格上的所有代码。

    Option Compare Database
`enter code here`Option Explicit
Private Sub Check158_Click()

    ' Try and change sql code
    Me.Combo35.RowSource = "SelectAllOrders"
End Sub

Private Sub Combo35_AfterUpdate()
                                                                                                                                                                                                                            Me.RecordsetClone.FindFirst "[OrderID] = " & Me![Combo35]
    Me.Bookmark = Me.RecordsetClone.Bookmark
    ' Find the record that matches the control.
End Sub

Private Sub Command122_Click()
On Error GoTo Err_Command122_Click


    DoCmd.Close

Exit_Command122_Click:
    Exit Sub

Err_Command122_Click:
    MsgBox Err.Description
    Resume Exit_Command122_Click

End Sub

Private Sub Customer_AfterUpdate()
Forms![Orders]![CustomerID] = [Forms]![Orders]![Customer].Column(0)

Forms![Orders]![Phone] = [Forms]![Orders]![Customer].Column(2)
End Sub

Private Sub Frame40_AfterUpdate()
'Forms![Orders]![Orders Subform].Form![Quantity]
If Forms![Orders]![Frame40] = 1 Then
   ' Me![Orders By Customer Subform].[Requery
   Forms![Orders]![Child81].Form![ProductID].RowSource = "StdPrice"
   Else
   Forms![Orders]![Child81].Form![ProductID].RowSource = "PvtPrice"
End If
End Sub
Private Sub Command131_Click()
On Error GoTo Err_Command131_Click

    Me![Invoice Total] = Forms![Orders]![Child81].Form![Order Subtotal]
    DoCmd.GoToRecord , , acNewRec

Exit_Command131_Click:
    Exit Sub

Err_Command131_Click:
    MsgBox Err.Description
    Resume Exit_Command131_Click

End Sub
Private Sub Command132_Click()
On Error GoTo Err_Command132_Click
    'Cancel Click for Orders

    If Me.Dirty Then DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    Me![Invoice Total] = Forms![Orders]![Child81].Form![Order Subtotal]
    DoCmd.Close


Exit_Command132_Click:
    Exit Sub

Err_Command132_Click:
    MsgBox Err.Description
    Resume Exit_Command132_Click

End Sub
Private Sub Command133_Click()
On Error GoTo Err_Command133_Click
    'Save and Exit Click

    Me![Invoice Total] = Forms![Orders]![Child81].Form![Order Subtotal]
    DoCmd.Close

Exit_Command133_Click:
    Exit Sub

Err_Command133_Click:
    MsgBox Err.Description
    Resume Exit_Command133_Click

End Sub
Private Sub Command134_Click()
On Error GoTo Err_Command134_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_Command134_Click:
    Exit Sub

Err_Command134_Click:
    MsgBox Err.Description
    Resume Exit_Command134_Click

End Sub
Private Sub Command136_Click()
On Error GoTo Err_Command136_Click

    DoCmd.GoToRecord , , acNext

Exit_Command136_Click:
    Exit Sub

Err_Command136_Click:
    MsgBox Err.Description
    Resume Exit_Command136_Click

End Sub
Private Sub Command138_Click()
On Error GoTo Err_Command138_Click

    Me![Invoice Total] = Forms![Orders]![Child81].Form![Order Subtotal]

    DoCmd.GoToRecord , , acNext

Exit_Command138_Click:
    Exit Sub

Err_Command138_Click:
    MsgBox Err.Description
    Resume Exit_Command138_Click

End Sub
Private Sub Command148_Click()
On Error GoTo Err_Command148_Click

    Dim stDocName As String

    stDocName = "Container Card"
    DoCmd.OpenReport stDocName, acPreview, , "[OrderID] = Forms![Orders]![OrderID]"

Exit_Command148_Click:
    Exit Sub

Err_Command148_Click:
    MsgBox Err.Description
    Resume Exit_Command148_Click

End Sub

Private Sub Form_Close()
'    Me![Invoice Total] = Forms![Orders]![Child81].Form![Order Subtotal]

End Sub

和SUB表格

Option Compare Database
Option Explicit


Private Sub Form_AfterDelConfirm(Status As Integer)
    Forms![Orders]![Child81].Requery
End Sub

Private Sub Form_Open(Cancel As Integer)
'If Forms![Orders]![Frame40] = 1 Then
'   Me![ProductID].RowSource = "StdPrice"
'   Else
'   Me![ProductID].RowSource = "PvtPrice"'
'End If


End Sub


Private Sub ProductID_NotInList(NewData As String, Response As Integer)
    MsgBox "Double-click this field to add an entry to the list."
    Response = acDataErrContinue
End Sub
Private Sub ProductID_AfterUpdate()
 Dim pos As Variant
    Me![UnitPrice] = Me![ProductID].Column(2)
    Me![ProductName] = Me![ProductID].Column(1)
    Me![GLAcct] = Me![ProductID].Column(3)
    Me.Dirty = False
End Sub
Private Sub ProductID_DblClick(Cancel As Integer)
On Error GoTo Err_ProductID_DblClick
    Dim lngProductID As Long

    If IsNull(Me![ProductID]) Then
        Me![ProductID].Text = ""
    Else
        lngProductID = Me![ProductID]
        Me![ProductID] = Null
    End If
    DoCmd.OpenForm "Products", , , , , acDialog, "GotoNew"
    Me!ProductID.Requery
    If lngProductID <> 0 Then Me![ProductID] = lngProductID

Exit_ProductID_DblClick:
    Exit Sub

Err_ProductID_DblClick:
    MsgBox Err.Description
    Resume Exit_ProductID_DblClick
End Sub

Private Sub Command20_Click()
On Error GoTo Err_Command20_Click


    DoCmd.GoToRecord , , acNewRec

Exit_Command20_Click:
    Exit Sub

Err_Command20_Click:
    MsgBox Err.Description
    Resume Exit_Command20_Click

End Sub
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click


    DoCmd.GoToRecord , , acNext

Exit_Command22_Click:
    Exit Sub

Err_Command22_Click:
    MsgBox Err.Description
    Resume Exit_Command22_Click

End Sub
Private Sub Command23_Click()
On Error GoTo Err_Command23_Click


    DoCmd.GoToRecord , , acFirst

Exit_Command23_Click:
    Exit Sub

Err_Command23_Click:
    MsgBox Err.Description
    Resume Exit_Command23_Click

End Sub
Private Sub Command24_Click()
On Error GoTo Err_Command24_Click


    DoCmd.GoToRecord , , acPrevious

Exit_Command24_Click:
    Exit Sub

Err_Command24_Click:
    MsgBox Err.Description
    Resume Exit_Command24_Click

End Sub
Private Sub Command25_Click()
On Error GoTo Err_Command25_Click


    DoCmd.GoToRecord , , acLast

Exit_Command25_Click:
    Exit Sub

Err_Command25_Click:
    MsgBox Err.Description
    Resume Exit_Command25_Click

End Sub
Private Sub Command26_Click()
On Error GoTo Err_Command26_Click


    DoCmd.GoToRecord , , acNext

Exit_Command26_Click:
    Exit Sub

Err_Command26_Click:
    MsgBox Err.Description
    Resume Exit_Command26_Click

End Sub

Private Sub Quantity_AfterUpdate()
Dim pos As Variant
'Me.Dirty = False

End Sub

Private Sub UnitPrice_AfterUpdate()
Dim pos As Variant
'Me.Dirty = False

End Sub
Private Sub Command33_Click()
On Error GoTo Err_Command33_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Command33_Click:
    Exit Sub

Err_Command33_Click:
    MsgBox Err.Description
    Resume Exit_Command33_Click

End Sub

1 个答案:

答案 0 :(得分:0)

第一个示例中的表单可能是数据绑定表单 - 它应该有一个数据源集,它将是用于填充表单上字段的查询或表。如果您在表单上编辑值并关闭表单,它将自动提交对该查询底层表的更改。

第二个示例有一些导航按钮...导航离开当前记录也应该自动导致提交。再次,查看表单的datasource属性以确定它正在更新的内容。