Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

How to make a checkbox control with a Null value appear white instead of greyed out.

Frm1 is based qry1. Qry1 is based on an outer join of tables tbl1 and tbl2 (the join is directed from tbl1 to tbl2). The controlsource of checkbox control chk1 on frm 1 is a boolean field of tbl2.

If there is no corresponding record in tbl2 for a given record in tbl1, then chk1 will appear greyed out (since it is Null). How can I make it appear white (False) when it has a Null valuel?
0
Milewskp
Asked:
Milewskp
  • 6
  • 5
  • 3
  • +2
2 Solutions
 
DockieBoyCommented:
Try using the Nz function,

Nz(MyControlSource,False)

Can you upload the db for a more specific answer :)
0
 
MilewskpAuthor Commented:
Hi Dockie,
Good suggestion, but Nz would make it read only, and in my case I need read write.
0
 
DockieBoyCommented:
Hmm, my bad, I thought it was read only from the sounds of the query your form is based on, I don't use a lot of bound forms, but I'll have a quick play :)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
DockieBoyCommented:
Sorry, I have just re read your post and I just want to be sure.  You have a Left Outer Join and the check box is included in the results but is null because there is no record that maches the Join critera.

Not sure how you would be able to make changes to the value of this check box anyway?

Can you please provide an example :)
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
I have a solution for you. This solution requires you to add a dummy field to one the tables. If you are okay with that, please let me know to discuss it.

Mike
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
If the answer is yes, then add chkDummy to  tbl1 with Yes/No setting. Now, on your form, binde your checkbox (chkbox1) to this field not the one from tble2.

Also, on your form add chkbox2 to be binded to yes/no from table2. Make chkbox2 invisible.

In the Current event of the form, have:

If chkbox2 = true then
   chkbox2 = true
Else
   chkbox2 =False
End If

Mike
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
Word of caution...

In the existing grayed out check box version, please test VarType of the check box when it is grayed out. In the Current even of form prior to applying my solution have:

MsgBox VarType(Me!chk1)

It may produce 9 when it is grayed out. Object VarType is 9. If it is 9, then the code should change to:


If VarType(chk1)=9 then
   chkbox2 =False
elseif chk1= True then
   chkbox2 =True
Else
   chkbox2 =False
End If

Use this version regardless. My last post needed some correction any way.

Mike

If chk1 = true then
   chkbox2 = true
Else
   chkbox2 =False
End If



0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:

 Nice to see you around Mike :)

JimD.
0
 
GRayLCommented:
Ditto :)
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
Thanks guys. I am here to learn some more from both of you.

Mike
0
 
MilewskpAuthor Commented:
Hi Mike,
Interesting idea. Thanks.  It got me thinking.

In my case the relationship between table1 and table2 is one-many, so changing the value of chkdummy in Table2 would affect multiple records on the form.
But, addingf the extra field to Table1 may be unneessary. What if chk1 is a calculated control:
= Nz([Chk2], False)

with OnClick event:
[chk2] = Nz([chk2], True)


- Your thoughts?
0
 
MilewskpAuthor Commented:
Hi all,
I've this and it seems to work (chk1 is greyed out when Null; chk2 is always white and checked or unchecked but always white):

chk1.Visible = False
chk2.Visible = True
chk2.Controlsource =Nz([Chk1],False)

Private Sub chk2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      Me.chk1 = Not Nz(Me.chk2, False)
End sub
0
 
MilewskpAuthor Commented:
Thanks for your help folks, I'll go with my solution and give the assist to Mike.
0
 
Mike EghtebasDatabase and Application DeveloperCommented:
Milewskp<

My appology for not responding earlier.

If you have a solution that you like that is fantastic. FYI, adding chkDummy and data in it is of no conseqyence (this is why it ia called dummy). The reason we wanted to have it so that the the visible check box is bound to something (this is essential if you are showing multible records in detail section).

This dummy checkbox, nonetheless, displays the accurate data from theother table. Also, just in case, you wanted to upload a sample datbase, I will be glad to work with you on it.

Regards,

Mike
0
 
MilewskpAuthor Commented:
Hi Mike,
I'm satisifed that this question is closed, but if you'd like to discuss further, post away.

Thanks again.
0
 
MilewskpAuthor Commented:
.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 5
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now