Disable a subform while editing data in another subform - vba

I have two subforms, the first is a list and the second is a detail record of the record selected in the first subform.
When I select the edit button in the detail subform I want to lock out the list form.
I tried: forms!master!subformList.enabled=false.
Note:
_D is the detailed subform.
_L is the list subform.
cmb_Edit is the edit/save button located on detail subform.
Private Sub EnableFutureForm(EF)
Select Case EF
Case 1 'SubForm Detail is Locked Down
FuturePaint (False)
Forms!FrmFutureWork!FrmFutureWork_D!cmb_Edit.Caption = "Edit"
Forms!FrmFutureWork!FrmFutureWork_L.Form.Enabled = True
Case 2 'SubForm Detail is Opened up
FuturePaint (True)
Forms!FrmFutureWork!FrmFutureWork_D!cmb_Edit.Caption = "Save"
Forms!FrmFutureWork!FrmFutureWork_L.Form.Enabled = False
Forms!FrmFutureWork!FrmFutureWork_D!cmb_TRMM.SetFocus
End Select
End Sub
I want the list subform to not respond to any click, while the Form_Click continues to work.

You can disable events by setting the forms property.
ForForm_Clickit is Form.OnClick property.
'disable event
Forms!FrmFutureWork!FrmFutureWork_L.Form.OnClick = vbNullString
'enable event
Forms!FrmFutureWork!FrmFutureWork_L.Form.OnClick = "[Event Procedure]"
Or you can add a check to the events-code:
Private Sub Form_Click()
If Forms!FrmFutureWork!FrmFutureWork_L.Enabled then
' Actions on subform-control (not the form!) enabled
Else
' Action on subform-control disabled
End IF
End Sub

Related

Hide record from continuous form if checkbox is marked in query

I have a continuous Form with records, the records contain a yes/no. So if the checkbox in the form is marked I want the record to be hidden from the form next time you open it, but it does not seem to work.
Private Sub Form_AfterUpdate()
If Me.Checkbox = False Then
Me.Checkbox.Visble = True
Else
Me.Checkbox.Visible = False
End If
End Sub
Add a Boolean field named Hidden having a DefaultValue of False in the table and, in the form, bind this field to the checkbox.
Then, when opening the form, filter on [Hidden] = False.

How do I hide/unhide a subform based on the input from two comboboxes?

I have a mainform, called TrainingsSU
In it I am calling subform qry_TrainingSU (built from the query of the same name)
I have it set up so that the records auto populate the subform based on the two comboboxes in the main form.
But what I need to do is hide the subform, and have it display only when the two comboboxes are populated and records are loaded.
Here's the current VBA (of which I am not really even a novice at)
Private Sub cbo_EmployeeLookup_AfterUpdate()
Me!qry_TrainingsSU.Requery
If Me.cbo_EmployeeLookup.Value = "" Then
Forms!qry_TrainingsSU.Visible = False
Else
Forms!qry_TrainingsSU = True
End If
End Sub
Private Sub cbo_TrainingName_AfterUpdate()
Me!qry_TrainingsSU.Requery
If Me.cbo_TrainingName.Value = "" Then
Forms!qry_TrainingsSU = False
Else
Forms!qry_TrainingsSU.Visible = True
End If
End Sub
I found the general form of this code in another answer, here: MS Access: Hide and Unhide subform based on drop down in Main Form
However the code doesn't seem to be working for me.
Currently the subform is set to Visible:No
So nothing shows up at all.
If I change that, it doesn't disappear and the empty subform is still visible.
This wouldn't be a problem, except I need to use this form for another query and want to layer them over eachother when the second subform is ready to be used.
Later this form will be used to push an UPDATE SET to a table based on the different subforms.
Is there something that is obviously wrong with the code, or did I miss a setting somewhere?
You can try this:
Private Sub updateStates()
Me!qry_TrainingsSU.Form.Requery
If (Me.cbo_EmployeeLookup.Value <> "" AND Me.cbo_TrainingName.Value <> "") Then
Me!qry_TrainingsSU.Visible = True
Else
Me!qry_TrainingsSU.Visible = False
End If
End Sub
Private Sub cbo_EmployeeLookup_AfterUpdate()
updateStates
End Sub
Private Sub cbo_TrainingName_AfterUpdate()
updateStates
End Sub
Forms!qry_TrainingsSU searches form opened as main form, not a subform.

Set a sub-form hidden field to visible, based on a check box status

C, Thank you for your input and encouragement! I have changed my form and script slightly, I am afraid I kept the if then statement as I am comfortable with the formatting. The script now works when the 'On Open'event runs.
Private Sub Form_Open(Cancel As Integer)
Me.ChkAlbumNotes.SetFocus
If Me.ChkAlbumNotes.Value = False Then
Me.lblAlbumNotes.Visible = False
Me.txtAlbumNotes.Visible = False
Me.btnAlbumNotes.Visible = True
Else
Me.lblAlbumNotes.Visible = True
Me.txtAlbumNotes.Visible = True
Me.btnAlbumNotes.Visible = False
End If
Me.TrackName.SetFocus
If Me.TrackName = " " Then
Me.btnAddRecord.SetFocus
Else
Me.btnNextRecord.SetFocus
End If
End Sub
This is fine when the form opens for the first time but I have a set of navigation buttons that are installed by the application as Macros. I cannot add my script to the On_Click event when the button is clicked, as On_Click is linked to the Macro. Is there a way to incorporate the script from the On_Load process to the pre-defined macro? Or can you suggest a neater way to achieve my requirements which are;
When the form opens,a check is made for the existence of a false value in the checkbox
if the check box is set to false, then the Notes Text Box and label are hidden and the notes button is visible.
If the check box has a true value, then the Notes text box and label are made visible and the button is hidden.
On completion of the test I check the field Track Name
if this is empty, I assume I am at the last record and give the Add New Record button the focus
If Track Name is not empty, then focus is set to Next Record button
when this button is clicked, the next record page opens and the process starts again.
Many Thanks
Mike
You should use the Form_Current event instead of Form_Open . This fires on starting the form (2 times) and everytime you move to another record.
Private Sub Form_Current()
Me.lblAlbumNotes.Visible = Me.ChkAlbumNotes.Value
Me.txtAlbumNotes.Visible = Me.ChkAlbumNotes.Value
Me.btnAlbumNotes.Visible = Not Me.ChkAlbumNotes.Value
If Me.TrackName = "" Then ' I suggest If Me.TrackName = " " being a typo and you want to check if empty ( that's why you should use vbNullString instead of "")
Me.btnAddRecord.SetFocus
Else
Me.btnNextRecord.SetFocus
End If
End Sub

SubForm won't Requery after MainForm Changes are made

I have an access 2010 database that has a main form 'MainForm' and a subform 'SubForm'. The SubForm is attached to the MainForm as a Subform/Subreport object. The user will select a unique identifier from a dropdown and the subform should use that identifier to pull up employee information on the subform. I have tried any number of ways to avail...
Private Sub Dropdown_Exit(Cancel As Integer)
If IsNull(Me!Dropdown) Or Me!Dropdown= "" Then
' nothing to do due to no one selected
Else
Forms!MainForm!SubForm.Requery
' Forms!SubForm.Requery
' DoCmd.OpenForm "SubForm",,,"[ID]=" & me!SubForm!ID,,acDialog
End If
End Sub
The commented out statements are only some of the things I have tried.
Thanks in advance
You should be able to do this without any code by specifying the LinkMasterField and LinkChildField properties of the subform control on your main form.
It is clear that LinkChildField should be set to ID in the form design mode. It looks like you'll want to set LinkMasterField to Dropdown. You can set the FilterOnEmptyMaster property to Yes to hide all records before the Dropdown is filled, or No to show all records before Dropdown is specified.
EDIT:
If LinkMaster/LinkChild are not appropriate, then code for Dropdown's AfterUpdate event. This fires after a choice is completed via keyboard or mouse. It should look like :
Private Sub Dropdown_AfterUpdate()
If Len(Me!Dropdown & "") = 0 Then
'' handle cleared Dropdown
Else
Subform.Form.Filter = "[ID] = " & Me!Dropdown
Subform.Form.FilterOn = True
End If
End Sub
Changing the filter should update the subform.

Show/Hide tab page from a combo box on a subform

I have been looking around the internet for ages trying to find this solution to a problem i've been having.
I have a form (Form1) which consists of tabs and a subform (subForm1). Within subForm1 I have a combo box which I want to assign an AfterUpdate Event to. If the combo box (in the subform) is yes, show tab1, else if combo box is no then hide tab1. The code I'm looking for is something like this :
Private Sub Combo52_AfterUpdate()
If Me.Combo52.Value = "Yes" Then
Forms!FrmAssessment.TabCtl50.Pages(5).Visible = True
ElseIf Me.Combo52.Value = "No" Then
Forms!FrmAssessment.TabCtl50.Pages(5).Visible = False
End If
Got any ideas?