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

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?

Related

Disable a subform while editing data in another subform

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

Removing Combo Box value without having to lose focus

I have a combo box with a list of customers which I am filtering as the user types.
When the form loads there is a preset value in the combo box, however when I backspace the combo box doesn't update the value (it keeps the original customer). The value will only become null once I click away from the combo box. Then I click back and it starts filtering as I type.
I tried setting the focus to another control and then coming back to the combo box on the AfterUpdate events but the code doesn't change the focus
Private Sub cboCustCode_AfterUpdate()
Me.txtCustName = DLookup("[CUST_NAME]", "[PLACE_HOLDER_CUST_LIST]", "[CUST_CODE] = '" & Me.cboCustCode & "'")
Me.txtCustName.SetFocus
Me.cboCustCode.SetFocus
End Sub
I want to be able to backspace in the combo box and then start typing and see the filtered results
I fixed it by checking if the combo box text length is 0 and then setting the combo box value = null
Private Sub cboCustCode_Change()
Me.txtCustName = DLookup("[CUST_NAME]", "[PLACE_HOLDER_CUST_LIST]", "[CUST_CODE] = '" & Me.cboCustCode & "'")
If Len(Me.cboCustCode.Text) = 0 Then
Me.cboCustCode = Null
End If
End Sub

Make combo box record as table field name , MS Access

I have combo box in form, i want to have it's drop down value to be Table fields name.Table name is tblCap, and the field are Year1,Year2 and Year3.I want that in the Combo box to have dropdown list as Year1,Year2,Year3 and when that year is selected it should display related field in subform.
Any help would be appreciated.
Thank you.
This is much simpler than you may imagine:
Open the Property sheet of the combobox, tab Data
Set RowSourceType: Value List
Set RowSource: "Year1";"Year2";"Year3"
To display the selected value (field name) in a subform, use this expression:
=[Parent]![NameOfYourCombobox]
To display, in a textbox on the main form, the value of the selected field name of the subform:
=[NameOfYourSubformControl].[Form]([NameOfYourCombobox])
or (?) on the subform:
=[Parent]([Parent]![NameOfYourCombobox])
Update after comments.
Once the RowSource has been set-up as per #Gustav answer, in order to hide/unhide the TextBox controls according to the value of ComboBox you need to set their Visible property to True/False.
On the Events tab set the AfterUpdate of your ComboBox control to [Event Procedure] and on the code behind file set the following:
Private Sub YourComboControlName_AfterUpdate()
With Me
Select Case .YourComboBoxName.Value
Case "Year1":
With .YourSubformName.Form
.Your2000TextBoxControlName.ColumnHidden = false
.Your2001TextBoxControlName.ColumnHidden = true
.Your2002TextBoxControlName.ColumnHidden = true
End With
Case "Year2":
With .YourSubformName.Form
.Your2000TextBoxControlName.ColumnHidden = true
.Your2001TextBoxControlName.ColumnHidden = false
.Your2002TextBoxControlName.ColumnHidden = true
End With
Case "Year3":
With .YourSubformName.Form
.Your2000TextBoxControlName.ColumnHidden = true
.Your2001TextBoxControlName.ColumnHidden = true
.Your2002TextBoxControlName.ColumnHidden= false
End With
End Select
End With
End Sub

Show value based on selection in combo box vba

I need to show denominations based on selection in combo box in my access form.
The tricky thing here is that I need to show immediately after selecting in the combo box (without saving it). This one is working just after I save my selection.
If cmb_Main_Impact.Value = "Productivity" Then
Me.txt_Units = "minutes"
End If
If cmb_Main_Impact = "Quality" Then
Me.txt_Units = "number of errors"
End If
That code should work fine. You want to put it in the combobox on change event.
Also added an elseif so there isnt multiple if and end ifs. Put that code in in the userform that has the combo box.
So your code will look like.
Private Sub cmb_Main_Impact_Change()
If cmb_Main_Impact.Value = "Productivity" Then
Me.txt_Units = "minutes"
elseIf cmb_Main_Impact = "Quality" Then
Me.txt_Units = "number of errors"
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.