"Mohammad Mobin" <mobin.net[ at ]gmail.com> wrote in message news:747BD3BD-BF7F-4725-8631-87969DCAFF50[ at ]microsoft.com...
[Quoted Text] > there are 4 fields in a table/form (3 of them are checkbox and one text) > so > the question is: > > How i can store a value for each time user puts a checkmark on individual > fields. > > Example: > option1 (yes/no checkbox) > option2 (yes/no checkbox) > option3 (yes/no checkbox) > result (text) > when user puts a checkmark on option1 so "New York" should be stored in > the > text field and when user puts checkmark on option2 so "New York, London" > should be stored in the text field. (New York as to come from option1 > checkmark and London should come from option2) > When user removes checkmark from option1 so the value in text field should > be only "London".
From your description, it sounds like the text string you're creating is entirely dependent on the values of the check boxes -- the text should always correspond exactly to the boxes that are checked. If that's true, there is no reason for the text box to exist at all. Instead, this value should be calculated whenever it is needed; either as a calculated control on a form or report, or as a calculated field in a query. An expression that would do that is (for example):
Mid(IIf(Option1, ", New York", "") & IIf(Option2, ", London", "") & IIf(Option3, ", Paris", ""), 3)
That expression will have been broken onto two lines by the newsreader, but it would have to be entered all on one line if used as a controlsource expression.
Note that if you use this as a controlsource expression, you must precede it with the = sign, to let Access know it's an expression. It's probably handiest, though, to create a query that calcuates the field, and just base your forms or reports on that query. For example, this SQL:
SELECT Option1, Option2, Option3, Mid(IIf(Option1, ", New York", "") & IIf(Option2, ", London", "") & IIf(Option3, ", Paris", ""), 3) AS Cities FROM YourTable;
-- Dirk Goldgar, MS Access MVP www.datagnostics.com
(please reply to the newsgroup)
|