I’m developing a DB application via MS Access 2010. I have added an unbound, binary checkbox to a report with the purpose that a user can choose one of two record sources (queries), for two variations of the report. The checkbox Control Source property is blank and the Triple State is set to No.
However, upon opening the report, the checkbox is permanently greyed out, no matter haw many times it is clicked! Also, upon each single click on the checkbox, my_checkbox_Click() fires twice with its value toggling between Null and True! The Null value seems to be interpreted as False which might be OK if the event didn't double-fire on each single click.
How do I get my checkbox to both appear properly -- as a binary checkbox, toggling between yes and no -- and function correctly, firing _Click() only once per click? If it's a known issue with no solution, which is the best button type as a workaround?
My code:
Private Sub Report_Load()
Debug.Print vbCrLf & "Report_Load"
Me.my_chk.Value = False
set_data_source
End Sub
Private Sub my_chk_Click()
Debug.Print vbCrLf & "my_chk_Click"
set_data_source
End Sub
Private Sub set_data_source()
Debug.Print vbCrLf & "set_data_source"
Debug.Print "Me.my_chk.Value", Me.my_chk.Value
Debug.Print "Me.my_chk.ControlSource ", Me.my_chk.ControlSource
Debug.Print "Me.my_chk.TripleState ", Me.my_chk.TripleState
Me.RecordSource = IIf(Me.my_chk.Value, "my_yes_qry", "my_no_qry")
Me.Requery
Debug.Print "Me.RecordSource", Me.RecordSource
End Sub
Immediate window:
Report_Load
set_data_source
Me.my_chk.Value False
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_no_qry
' click once on checkbox
my_chk_Click
set_data_source
Me.my_chk.Value Null
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_no_qry
my_chk_Click
set_data_source
Me.my_chk.Value -1
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_yes_qry
' click once on checkbox
my_chk_Click
set_data_source
Me.my_chk.Value Null
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_no_qry
my_chk_Click
set_data_source
Me.my_chk.Value -1
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_yes_qry
The only good news is that the Requery after a RecordSource changes does correctly (if all-too-briefly) affect the data.
Another thing, even though my checkbox doesn't have an AfterUpdate listed under Events, if I replace the above my_checkbox_Click() handler with
Private Sub my_chk_AfterUpdate()
Debug.Print vbCrLf & "my_chk_AfterUpdate"
set_data_source
End Sub
I get
Report_Load
set_data_source
Me.my_chk.Value False
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_no_qry
' click once on checkbox
my_chk_AfterUpdate
set_data_source
Me.my_chk.Value -1
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_yes_qry
' click once on checkbox
my_chk_AfterUpdate
set_data_source
Me.my_chk.Value -1
Me.my_chk.ControlSource
Me.my_chk.TripleState False
Me.RecordSource my_yes_qry
which, as you can see, doesn't work either because now, even though AfterUpdate fires once per click, the checkbox value doesn't change!
Over at http://ift.tt/1gyrfxu there was a suggestion (regarding a form, not a report) to use fancy coding
Nz(Me.my_chk = True, False)
which I tried but it had no difference in outcome.
Aucun commentaire:
Enregistrer un commentaire