Hide Column/Field In query based on checkbox (1 Viewer)

GinaWhipp

AWF VIP
Local time
Today, 18:55
Joined
Jun 21, 2011
Messages
5,901
Okay, I get it. (And thanks for clearing that up. We don't mind if you post elsewhere we just like to know about it so we volunteers aren't double timing in our spare time.)

Unfortunately, there no *easy* way to do this with a check box. Deleting the column(s) might be but will still require some code. That said, you could just separate queries, not THAT would be easy.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:55
Joined
May 21, 2018
Messages
8,463
Unless I am reading this completely wrong you are making it way to hard. You are not dynamically picking different fields to show. You want two queries, one has X fields the other has X-3 fields. Forget about deleting fields, simply make two queries. If you want a checkbox, or toggle button, or combobox whatever. You choose something and pick which query to load. If it is shown in a subform simply change the source object of the subform.
 

KathCobb

Registered User.
Local time
Today, 15:55
Joined
Jun 29, 2012
Messages
46
You are 100% correct.....making it way to hard. Here is all I have for my button click:

Code:
Private Sub cmdRunQuery_Click()

If Me.ckboxTrustAnnuityInfo = -1 Then
DoCmd.OpenQuery "qryListExportTrustInfo", acViewNormal
Else: DoCmd.OpenQuery "qryListExport", acViewNormal
End If

End Sub

I just copied my original query, renamed it and kept the fields I wanted and in the original query deleted the ones I didn't.

Just one more question....
The code above actually opens the query as a datasheet. If I want it to export directly to excel, which DoCmd do I use? Would DoCmd.Transferspreadsheet work?


Thank you every one here who contributed, it all gave me food for thought and suggestions to research
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:55
Joined
Feb 19, 2013
Messages
16,553
yes use docmd.transferspreadsheet. no need to open the query
 

Users who are viewing this thread

Top Bottom