views:

120

answers:

1

Warning: I am very new to Access coding. I am used to .NET and PHP

I just converted an Access 95 program to Access 2007 and I got it all working now I am trying to make some updates.

I have a form that updates a table in the database but I can't find an attached query or anywhere where it actually does a SQL statement. Please help. And thank you.

This is all the code on the one form.

    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

And a SUB form

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
A: 

The form in your first example is likely a databound form - it should have a datasource set, which will be the query or table used to populate the fields on the form. If you edit values on the form, and close the form, it will automatically commit changes to the tables underlying that query.

The second example has some navigation buttons...navigating away from the current record should automatically cause a commit as well. Again, look at the datasource property of the form to work out what it's updating.

YogoZuno
AWESOME! Haha thank you very much it all (kind of) makes sense now.Is their a way I could make some fields required so it can't commit without those fields filled out?
Bruno43
If you're going to work with Access, you need to learn how to use it interactively. This means learning how to create tables in the Access UI and then how to create bound forms to edit those tables. There is no code needed for any of this -- it's all done for you behind the scenes. Much of the code you've posted is doing nothing at all, and my bet is that many of those subroutines are no longer even attached to the controls they are named after.
David-W-Fenton
@David I would be willing to do this. Do you recommend any good Online resources?
Bruno43
I would have to Google to find any online resources (i don't need them, as I learned how to use Access interactively in 1996!) -- I think you can probably Google just as well as I can. You might check out http://mvps.org/access/ because that might have pointers to Gettin Started-type sites. Also, http://www.granite.ab.ca/access/ and http://allenbrowne.com are likely to have good links for getting started, but neither is a site designed as a tutorial. Surely the Access Help has some kind of link to MS's online tutorials (I can't check as I block Access in my firewall).
David-W-Fenton
Consider a book: http://stackoverflow.com/questions/1457865/ms-access-2003-good-book-on-learning-advanced-vba
Remou
@David Yup been googling all day long, was just wondering if their might be some gem that I was missing. @Remou Will do. Thanks
Bruno43