Pergunta

I'm a newbie to VBA, and will try to make my question clear. I want to add another If Else statement to say when the button OR is clicked, it should to certain stuff else other. So my question is do I have to code anything within Private Sub OR_Click() ... End Sub first then reference it in my new If Else statement?

If .RecordCount > 0 Then
    .MoveFirst 
    Do While Not .EOF
        If Filter Is Nothing Then
            Set Filter = XFormToFilter.FilterBuilder
            Filter.SetPrimaryFilter PrimaryFilter, primaryTable, primaryKey
        End If  
        'This is where I want the button to go

        Filter.AddSubFilter "Filter" & .fields("ID"), _
            filterString, targetTable, subformDict(targetTable)
        .MoveNext
    Loop
End If

Thanks a bunch!

Foi útil?

Solução

You should have created a toggle button in the form designer (not a standard button). Every control has a generic Name which Access will set unless you change it -- something like ToggleButton115. You can then write code within the filter handler like this:

If ToggleButton15 Then
    'OR option has been set; change the filter appropriately
Else
    'OR option has not been set
End If

NB: This works because the togglebutton's Value property is True or False depending on whether it has been toggled or not. The Value property is the default property -- the property VBA assumes you want to use when you don't specify a property on an object.

See here for more details.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top