Solved

Access 2007 how (or is it possible) to have a query expression return a checkbox to display the value?

Posted on 2010-11-30
5
572 Views
Last Modified: 2012-05-10
I have a table in which is indicated whether one service is marketed with Other Service A or Other Service B. Answer is one of two chosen from a drop down menu so the data is in text form.

I have 2 fields in a query with expressions that successfully return a true/false or yes/no (have tried both to no avail) in an attempt to convert the data Other Service A or Other Service B to T/F or Y/N which is displayed on a form as two check boxes. The problem is that they will DISPLAY as check marks, but I can't change it in the form like I can a regular check box.

Is there a way around this?
0
Comment
Question by:Laura Sheldon
5 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 125 total points
ID: 34241374
Is the column a Text column or a Numeric column? Checkboxes work with Numeric datatypes (preferably Boolean). If the field you're working with is a Text field, you'll have to change the design to manage this.

0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 125 total points
ID: 34241903
I'm confused.  Do you mean that you have this field setup in tabledesign with a lookup, so you can select either "Other Service A" or "Other Service B" from the dropdown in table view?  If so, why aren't you doing the same thing in your form?  Why use checkboxes instead of a combo box?

If you really want to use checkboxes, you are going to have to make them unbound, and add code to them to change the value as appropriate.  Get rid of the expression in your query and just use the original field.

Then, in the forms Current event, use the expression you had in your query to determine what the value of the checkbox should be, something like:

Private Sub Form_Current

    me.chk_ServiceA.Value = iif(me.[SomeFieldName] = "Other Service A", True, False)
    me.chk_ServiceB.Value = iif(me.[SomeFieldName] = "Other Service B", True, False)

End Sub

Then, use the Click event of the checkbox, to set the value of the field, something like:

Private sub chk_ServiceA_Click

    me.[SomeFieldName] = iif(me.chk_ServiceA, "Other Service A", "")

End Sub

But with this technique, you will also have to add some code that would uncheck chk_OtherServiceB when chk_OtherServiceA is clicked, since it cannot be both at the same time.

A better technique would be to use an unbound option group, with either checkboxes or radio buttons.  With this technique, you would use the Form_Current event to set or the value of the option group based on the value in your field.  Then use the option groups click event to set the value of the form based on the selection.

0
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 125 total points
ID: 34242039
Try this: I am using table t (f1 As Text)
f1
Other Service A
Other Service B
Other Service A
Other Service B
Other Service A

SELECT t.f1, [f1]="Other Service A" AS yn
FROM t;
f1                     yn
Other Service A      -1
Other Service B      0
Other Service A      -1
Other Service B      0
Other Service A      -1

0
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 125 total points
ID: 34242997
Alternatively, remove the checkbox and replace it with a textbox bound to the same field, and make the format Yes/No.
0
 

Author Closing Comment

by:Laura Sheldon
ID: 34250663
All great input! Thanks for the help!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now