Option group not working

ClaraBarton

Registered User.
Local time
, 20:28
Joined
Oct 14, 2019
Messages
574
1730149718421.png

To keep from dragging things down I have a default of choosing only the current year transactions.
  1. If I choose Current year, it works
  2. If I choose All, it works
  3. If I choose Current year after choosing all, it works
  4. I cannot choose All after choosing current year. It just keeps returning current year even if I click on a new account. It stays current year.
  5. Code:
    Private Sub TransactionBtn_Click()
    Dim intDate As Integer
    intDate = Me!frameLimit
        
        Select Case intDate
            Case 1   'Current Year
                DoCmd.OpenForm "frmRegister", _
                 WhereCondition:="Year([CkDate]) = " & Year(Date)
    
            Case 2    'All Transactions
                DoCmd.OpenForm "frmRegister"
                    
        End Select
          
            'Change register if click on an different account
        If IsLoaded("frmRegister") Then
            Forms!frmRegister.Requery
        End If
    End Sub
 
When you say you cannnot choose All, are you saying the selection doesn't change, or just the code is not branching to that block?
 
The selection works fine, just the transactions don't change. I wonder if having no WhereCondition assumes the same as first? How do you say "no WhereCondition"?
 
If the form is already open, change its FilterOn property to False in your code.
 
Make sure the form is closed before you open it. Opening a form that is already open does not requery the RecordSource. You can add additional filters and so that is why current works after all but not vice versa.
 
It needs to stay open.... I switch between accounts on one form to change the transactions on the other. Same for date. Note the last three lines. Would a requery be required somewhere? I tried one before option 2 but doesn't change the records.
 
The selection works fine, just the transactions don't change. I wonder if having no WhereCondition assumes the same as first? How do you say "no WhereCondition"?
What happens if you try it this way?
Code:
    Select Case intDate
        Case 1   'Current Year
            DoCmd.OpenForm "frmRegister", _
             WhereCondition:="Year([CkDate]) = " & Year(Date)

        Case 2    'All Transactions
            DoCmd.OpenForm "frmRegister", WhereCondition:="1=1"
              
    End Select
 
You could also adjust your logic slightly:
Code:
Private Sub TransactionBtn_Click()
     
  If IsLoaded("frmRegister") Then
    Forms.frmRegister.Requery
  Else
    DoCmd.OpenForm "frmRegister", _
                   WhereCondition:="Year([CkDate]) = " & Year(Date)
  End If
  Forms.frmRegister.FilterOn = (Me.frameLimit = 1)
 
End Sub
 
WhereCondition:="1-1" Works too! What does that even mean? Thank you for your help.

The WHERE condition is actually just a list of sub-expressions linked by AND, OR, or XOR, and with possible prefixes of NOT. Usually each sub-expression is a tiny conditional expression that will evaluate to TRUE or FALSE. Like "X>3" or "A=B" or "Name LIKE 'Smith*'" A record is selected when its WHERE clause returns a TRUE for whatever is in that clause. Therefore, a clause like "WHERE 1=1" returns TRUE no matter what is in the record. Not sure what you mean by "1-1 works", because that would evaluate to FALSE uniformly and thus should return NO records.
 
Not sure what you mean by "1-1 works", because that would evaluate to FALSE uniformly and thus should return NO records.
I didn't test, but wondered whether it might be interpreted as a literal string rather than an expression - obviously, now that I have had some sleep, I can see that it shouldn't (be interpreted as a string, since there are no quote marks) so I'm not sure why it worked for the OP ???
 
IF it happens to be interpreted as a string for some reason, then the rules for BOOLEAN coercion are (I believe) that the first byte of the string compels the value. In the case of ASCII strings, only a string of one or two ASCII NUL characters would return FALSE. All other strings would return TRUE. It IS possible that the first TWO characters would compel the value since, if I recall correctly, the BOOLEAN data type is actually not a BYTE integer but instead is a WORD integer. But I would have to look up string-to-Boolean coercion to be sure and at the moment I have something else going on.
 
IF it happens to be interpreted as a string for some reason
No, it was just late last night when I was replying and ClaraBarton said it worked so I didn't double-check against what DBG actually typed to see that it was actually a typo.

So my needing sleep state conjured up a reason why it might have worked (interpretation as a string literal).

Really I was trying to write:
"If it works for you then it is down to dumb luck"
 

Users who are viewing this thread

Back
Top Bottom