Access Programming - FormsCalculating Totals on SubformWhen calculating sum on a subform don’t use calculated field in subform as it can be invalid if there is no data. Often find that it updated after you need it. Public InSubForm As Boolean
Private Sub JobItem_Enter()
InSubForm = True
End Sub
Private Sub JobItem_Exit(Cancel As Integer)
InSubForm = False
Call JobTotal
End Sub
Public Sub JobTotal()
Me.TotalAmount = DSum("Amount", "JobItem", "JobID = " & Me.JobID)
End SubUpdating Mainform from SubformIf a form on the main form needs to be updated when changes are made on the subform, use the subform Exit event:
Private Sub JobItem_Exit(Cancel As Integer)
Call JobTotal
End Sub
Public Sub JobTotal()
Me.TotalAmount = DSum("Amount", "JobItem", "JobID = " & Me.JobID)
End SubRefreshing Data Updated on Other FormsIf a combobox on a form has new entry added whilst the form is open, the simplest way cater for this, is in the forms Activate event to requiery the combobox. (The activate will always be triggered if the user navigates away to another form and then returns.) Hide Datasheet ColumnMe!TaskSubform.Form!Noted.ColumnHidden = True More on datasheet resizing and repositioning columns Comboxes Delete with Single KeyIf a combobox has a selected item, and you later want to clear it. You would either have to select the entire text and press backspace, or delete character by character. By intercepting the KeyDown event on the dropdown to check for backspace or del keys you make this much easier. Private Sub sectorId_KeyDown(KeyCode As Integer, Shift As Integer) Filter Subform by Search Text and Combo; Filter as User TypesWhen filtering a subform based on a search criteria the user enters, in order to detect the last key you have to use the .Text property. This is only valid if the control has the focus, so the code in the function CurrentValue will then return the .Value property. ' C O N T R O L S Call Subform Procedure/FunctionForms!Timesheet!ExpenseSubform.Form.FilterChange ' Call statement does not workDelete Record in Datasheet/Continuous FormThe following method works on a continuous form, but not on a datasheet: Private Sub HourID_DblClick(Cancel As Integer) ' Field on form The follwing works on a datasheet:
Private Sub HourID_DblClick(Cancel As Integer) ' Column field on datasheet Saving Current Record : Docmd.RunCommand or Me.Dirty = FalseAccess applies the RunCommand acCmdSaveRecord to whichever form happens to have focus. That may not be the form that is running the code. Me.Dirty is safer, because you are specifying which form record to save. Save Subform Before Updating Records via QueryAn error can occur when there are unsaved records (particularly a new record) in a subform and some control event, on the main form, triggers a bulk update of all records displayed in the subform. Unless subform is saved first, running an update query will give a record updated by other user error. Private Sub Hourlyrate_LostFocus() ' Field on Main form |
Resources Articles Access Database
|