Most of the forms in my database are either unbound, or bound to a table or query. On all of these forms I use button controls to save a record, cancel, close the form, or add a new entry.
In one form, I have a main form and a subform (see illustration). The main form contains read-only information, while the subform contains assignment details, which can be updated. New assignments can also be added.
To be consistent with the other forms in the database, I want the user to be able to click on a button to save the changes before they are committed to the database, or to cancel the operation, etc. However, the problem I'm running into is the buttons are on the main form, but I need them to control, in most cases, the action on the subform. I have them on the main form for aesthetic reasons and to be consistent with the other forms in the database.
As an example, this is what my Save code looks like on a normal form:
In the above code, txtProperSave and Label78 are on the main form, but the records being affected are in the subform.
Any insight and help would be appreciated.
In one form, I have a main form and a subform (see illustration). The main form contains read-only information, while the subform contains assignment details, which can be updated. New assignments can also be added.
To be consistent with the other forms in the database, I want the user to be able to click on a button to save the changes before they are committed to the database, or to cancel the operation, etc. However, the problem I'm running into is the buttons are on the main form, but I need them to control, in most cases, the action on the subform. I have them on the main form for aesthetic reasons and to be consistent with the other forms in the database.
As an example, this is what my Save code looks like on a normal form:
Code:
Private Sub cmdSave_Click()
'Move the focus to the Hidden field
Me.txtHidden.SetFocus
Select Case MsgBox("Do you want to save your changes to the current record?" & vbCrLf & vbLf & " Yes: Saves Changes" & vbCrLf & " No: Does NOT Save Changes" & vbCrLf & " Cancel: Reset (Undo) Changes" & vbCrLf, vbYesNoCancel + vbQuestion, "Save Current Record?")
Case vbYes: 'Save the changes
Me.txtProperSave.Value = "Yes"
Forms!Assignment_subform!DoCmd.RunCommand acCmdSaveRecord
Case vbNo: 'Do not save or undo
'Do nothing
Case vbCancel: 'Undo the changes
DoCmd.RunCommand acCmdUndo
Me.txtProperSave.Value = "No"
Case Else: 'Default case to trap any errors
'Do nothing
End Select
Label78.Visible = False
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
In the above code, txtProperSave and Label78 are on the main form, but the records being affected are in the subform.
Any insight and help would be appreciated.
Attachments
Last edited: