Hi
This is my first post on english language, so if i made some mistakes, sorry.
I have a main form with few command buttons and subform-hole.
Each command button open in subform-hole acctualy same subform with different filter.
For filtering subforms I used code:
Private Sub Command123_Click()
Me.subEmployeesHole.SourceObject = "subDepartment123"
With Me.subEmployeesHole.Form
.Filter = "Department = '123'"
.FilterOn = True
End With
End Sub
On that way when I press button "123" I have on subform only employes of 123 department (In MainTable which is source for all subforms exist column with departments name). But, on each subform I have a combo box (Search_Surname) for quick finding employees on just selected department. Row source for combo box is like:
SELECT MainTable.Name_and_FamilyName
FROM MainTable
WHERE (((MainTable.Department)="123"))
ORDER BY MainTable.Name_and_FamilyName;.
And AfterUpdate Event Procedure on Combo box is :
Private Sub Search_Surname_AfterUpdate()
Call SearchSurnameF
End Sub
SearchSurnameF is:
Function SearchSurnameF()
On Error GoTo SearchSurnameF_Err
DoCmd.SearchForRecord , "", acFirst, "[Name_and_FamilyName] = " & "'" & Screen.ActiveControl & "'"
SearchSurnameF_Exit:
Exit Function
SearchSurnameF_Err:
MsgBox Error$
Resume SearchSurnameF_Exit
End Function
Problem is that I don't know how to reduce number of subforms. In present
moment I have 15 exactly the same subforms which is difference only in Search_surname combo box, and number of subforms still growing.
Is there any way to put some additional code on command buttons on main form and eliminate all but one subforms?
I'm not very familiar with VBA, so anyone can help, please?
This is my first post on english language, so if i made some mistakes, sorry.
I have a main form with few command buttons and subform-hole.
Each command button open in subform-hole acctualy same subform with different filter.
For filtering subforms I used code:
Private Sub Command123_Click()
Me.subEmployeesHole.SourceObject = "subDepartment123"
With Me.subEmployeesHole.Form
.Filter = "Department = '123'"
.FilterOn = True
End With
End Sub
On that way when I press button "123" I have on subform only employes of 123 department (In MainTable which is source for all subforms exist column with departments name). But, on each subform I have a combo box (Search_Surname) for quick finding employees on just selected department. Row source for combo box is like:
SELECT MainTable.Name_and_FamilyName
FROM MainTable
WHERE (((MainTable.Department)="123"))
ORDER BY MainTable.Name_and_FamilyName;.
And AfterUpdate Event Procedure on Combo box is :
Private Sub Search_Surname_AfterUpdate()
Call SearchSurnameF
End Sub
SearchSurnameF is:
Function SearchSurnameF()
On Error GoTo SearchSurnameF_Err
DoCmd.SearchForRecord , "", acFirst, "[Name_and_FamilyName] = " & "'" & Screen.ActiveControl & "'"
SearchSurnameF_Exit:
Exit Function
SearchSurnameF_Err:
MsgBox Error$
Resume SearchSurnameF_Exit
End Function
Problem is that I don't know how to reduce number of subforms. In present
moment I have 15 exactly the same subforms which is difference only in Search_surname combo box, and number of subforms still growing.
Is there any way to put some additional code on command buttons on main form and eliminate all but one subforms?
I'm not very familiar with VBA, so anyone can help, please?
Last edited: