I am new to access and am having a problem with filtering. Here is a little bit of my setup: I have a main form that has a listbox so that users can choose one or many groups in which to display information about. The control name of the listbox is "grupos". The name of the field it is sorting is "Grupo_Nomb re". From the user“s selection, they can open up differing forms using command buttons that display filtered information about either members of "grupos", activities of "grupos", or objectives of "grupos".
The filter is working well EXCEPT for when the user selects a field on the listbox where there is no data entered yet. For example, one field in "grupos" may have records for objectives but no records for activities added yet. When the user tries to open the form based on the selected field with no records, it is completely blank.
I have created a form where a user can enter a new record for an activity, is there any way to open this form automatically if there is no record present as to add one...maybe using a conditional recordcount function to open the form if records for a certain field = 0?
I think I am a being a little confusing, so I will copy the code that is currently in place for the open event of the form based on the listbox query:
Private Sub EditarActividad es_Click()
Dim varItem As Variant
Dim strNombre_Grupo As String
Dim strFilter As String
If SysCmd(acSysCmd GetObjectState, acForm, "ActividadesNoM odificar") <> acObjStateOpen Then
DoCmd.OpenForm "ActividadesNoM odificar"
End If
For Each varItem In Me.grupos.Items Selected
strNombre_Grupo = strNombre_Grupo & ",'" & Me.grupos.ItemD ata(varItem) _ & "'" Next varItem
If Len(strNombre_G rupo) = 0 Then
strNombre_Grupo = "Like '*'"
Else
strNombre_Grupo = Right(strNombre _Grupo, Len(strNombre_G rupo) - 1)
strNombre_Grupo = "IN(" & strNombre_Grupo & ")"
End If
strFilter = "[Nombre_Grupo] " & strNombre_Grupo
With Forms![ActividadesNoMo dificar]
.Filter = strFilter
.FilterOn = True
End With
End Sub
The filter is working well EXCEPT for when the user selects a field on the listbox where there is no data entered yet. For example, one field in "grupos" may have records for objectives but no records for activities added yet. When the user tries to open the form based on the selected field with no records, it is completely blank.
I have created a form where a user can enter a new record for an activity, is there any way to open this form automatically if there is no record present as to add one...maybe using a conditional recordcount function to open the form if records for a certain field = 0?
I think I am a being a little confusing, so I will copy the code that is currently in place for the open event of the form based on the listbox query:
Private Sub EditarActividad es_Click()
Dim varItem As Variant
Dim strNombre_Grupo As String
Dim strFilter As String
If SysCmd(acSysCmd GetObjectState, acForm, "ActividadesNoM odificar") <> acObjStateOpen Then
DoCmd.OpenForm "ActividadesNoM odificar"
End If
For Each varItem In Me.grupos.Items Selected
strNombre_Grupo = strNombre_Grupo & ",'" & Me.grupos.ItemD ata(varItem) _ & "'" Next varItem
If Len(strNombre_G rupo) = 0 Then
strNombre_Grupo = "Like '*'"
Else
strNombre_Grupo = Right(strNombre _Grupo, Len(strNombre_G rupo) - 1)
strNombre_Grupo = "IN(" & strNombre_Grupo & ")"
End If
strFilter = "[Nombre_Grupo] " & strNombre_Grupo
With Forms![ActividadesNoMo dificar]
.Filter = strFilter
.FilterOn = True
End With
End Sub
Comment