473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

form checkboxes correspond to table entry

Okay here goes,

I have 3 tables

[Person Table]
Person_ID: text;
first_name: text;
last_name: text;

[Group_Definition Table]
Group_ID; Autonumber;
Group_Desc: Text;

[Person_Group_Membership]
person_id: text;
Group_ID; number;

Sample Data

[Person Table]
aaaa Jim Johnson
bbbb Joe Jones
cccc John Doe

[Group_Definition Table]
1 GroupA
2 GroupB
3 GroupC

[Person_Group_Membership]
aaaa 1
bbbb 1
aaaa 2
cccc 3

Now, I would like to have a form, where it lists the persons name, and a group of check boxes, one checkbox for each group. as you scroll through the people, there is a check in the box if the person has an entry in that group; also, if a check is placed in the box, a corresponding entry is made in the person_Group_membership table.

I am just not sure of the proper way to go about doing this. Thanks!
Oct 22 '07 #1
11 2454
NeoPa
32,556 Expert Mod 16PB
Nicely worded question :)
Unfortunately I think this is a CrossTab query question (not an area I'm very good in).
I think though, that a crosstab query of the groups per user would be required. It would not be updateable though, so would require code in the AfterUpdate events of the CheckBoxes to add and delete records as and when checked. Such code would always need to be succeeded with a call of Me.Requery. Does this make sense?

PS. You may get some other, better ideas from the other Experts.
Oct 22 '07 #2
FishVal
2,653 Expert 2GB
Hi, gixxer.

It will require some unusual design of the form.
  • the simplest way to represent person's membership is to use subform (datasheet or continuous forms view), lets say main form based on [Person Table] is [frmPeople], subform is [frmMembership]
    • as soon as you want to see all groups with checkboxes indicating membership the recordsource for form object of this subform should be outer join of [Group_Definition Table] and [Person_Group_Membership], like the following
      Expand|Select|Wrap|Line Numbers
      1. SELECT [Group_Definition Table].Group_Desc, IIf(IsNull(t.Person_ID),False,True) AS blnBelongsTo, [Group_Definition Table].Group_ID
      2. FROM [Group_Definition Table] LEFT JOIN (SELECT [Person_Group_Membership].* FROM [Person_Group_Membership] WHERE [Person_Group_Membership].Person_ID=Forms!frmPeople!Person_ID) AS t ON [Group_Definition Table].Group_ID = t.Group_ID;
      3.  
      note: controlsource for future checkbox is calculated field [blnBelongsTo], [Person_Group_Membership] is filtered by Forms!frmPeople!Person_ID prior to join because native Access form/subform link via master/child fields will not work
    • you need to bind the query fields to [frmMembership] controls ([Group_ID] control should be invisible)
    • [frmMembership] properties: allow additions/deletions/edit/filters should be set to "no"
  • the action check/uncheck person's membership in group actually means append/delete record to/from [Person_Group_Membership]
  • you may handle [blnBelongsTo] checkbox MouseDown event to run appropriate append/delete queries. Something like this:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub blnBelongsTo_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.  
    3.     'Exit sub if parent form on *New record* or other than Leftbutton was pressed
    4.     If IsNull(Me.Parent!keyPersonID) Or Button <> 1 Then Exit Sub
    5.  
    6.     With DoCmd
    7.         .SetWarnings False
    8.         Select Case Me.blnBelongsTo
    9.             Case True
    10.                 .RunSQL "DELETE * FROM [Person_Group_Membership] WHERE Person_ID='" _
    11.                     & Me.Parent!keyPerson_ID & "' AND Group_ID=" & _
    12.                     Me.Group_ID & ";"
    13.             Case False
    14.                 .RunSQL "INSERT INTO  [Person_Group_Membership] (Person_ID, Group_ID)" & _
    15.                     " VALUES ('" & Me.Parent!Person_ID & ", " & _
    16.                     Me.Group_ID & ");"
    17.         End Select
    18.         .SetWarnings True
    19.         Me.Requery
    20.     End With
    21.  
    22. End Sub
    23.  
Oct 22 '07 #3
Any chance the response could be re-posted?

Some of the text in the first code example has been truncated to be nothing more than the letter "T" making it a bit difficult to follow...

big thanks if you can,
mark
Feb 22 '16 #4
Rabbit
12,516 Expert Mod 8TB
Which post are you referring to? I don't see anything cut off. Did you scroll to the right in the code box?
Feb 22 '16 #5
in the first block of code:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Group_Definition Table].Group_Desc, IIf(IsNull(t.Person_ID),False,True) AS blnBelongsTo, [Group_Definition Table].Group_ID
  2. FROM [Group_Definition Table] LEFT JOIN (SELECT [Person_Group_Membership].* FROM [Person_Group_Membership] WHERE [Person_Group_Membership].Person_ID=Forms!frmPeople!Person_ID) AS t ON [Group_Definition Table].Group_ID = t.Group_ID;
you'll note that a few time there is a letter "t", which refers to something...
Feb 22 '16 #6
Rabbit
12,516 Expert Mod 8TB
You mean the "t." ? That's not cut off. It's referring to an alias given to the table.
Feb 22 '16 #7
NeoPa
32,556 Expert Mod 16PB
As Rabbit says that is an ALIAS defined in the SQL. It may help to see it all laid out in a more readable format :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Group_Definition Table].Group_Desc
  2.      , IIf(IsNull(t.Person_ID),False,True) AS blnBelongsTo
  3.      , [Group_Definition Table].Group_ID
  4. FROM   [Group_Definition Table]
  5.        LEFT JOIN
  6.        (SELECT [Person_Group_Membership].*
  7.         FROM   [Person_Group_Membership]
  8.         WHERE  [Person_Group_Membership].Person_ID=Forms!frmPeople!Person_ID) AS t
  9.   ON   [Group_Definition Table].Group_ID = t.Group_ID;
Always bear in mind, if you can't read it well on the page then you can always copy and paste it into something more controllable (EG. Notepad.) and read it there ;-)
Feb 23 '16 #8
I sincerly appreciate your reply, and at the same time apologize...
"alias" is something that as a self-taught blah, blah..., I'm aware of, but haven't yet given myself much experience with.

never-the-less,
I'm combing thru the code and the text of the page, and I can't seem to locate where the alias has been assigned.
I would think that it is in the first line of code:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Group_Definition Table].Group_Desc, 
  2. IIf(IsNull(t.Person_ID),False,True) AS blnBelongsTo, [Group_Definition Table].Group_ID 
  3.  
where t would then refer to the [Group_Definition Table], but the code then goes on to reference the field (t.Person_ID) which is not part of that table.

For the moment (rather then getting side tracked in learning about "alias"), would you tell me which table 't' refers to (I presume either: [Person Table] or [Person_Group_Membership] )

With thanks in advance,
Mark
Feb 23 '16 #9
Rabbit
12,516 Expert Mod 8TB
NeoPa's reformatted code block, line number 8, at the very end
Feb 23 '16 #10
AH.
BIG THANKS!
m.
Feb 23 '16 #11
NeoPa
32,556 Expert Mod 16PB
For anyone else struggling with that, the subquery (in parentheses - See Subqueries in SQL) is ALIASed in order to refer to it directly.

ALIAS simply means to assign a new name to a construct. This can be for tables, fields, queries, subqueries defined within parentheses, etc.

In SQL this is done using the ALIAS keyword, which can be abbrviated to AS as well as left out completely. Here are some illustrative examples :
Expand|Select|Wrap|Line Numbers
  1. SELECT [tblEmployee].[Employee ID] ALIAS [EmpID]
  2.      , [tblEmployee].[Employee Name] AS [EmpName]
  3. FROM   [Employee Table] [tblEmployee]
This illustrates each possibility. I've underlined the ALIAS in each case.
Feb 24 '16 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Emanuel Marciniak | last post by:
Hi all, We have the form which uses checkboxes for several fields and the target action points to outside webservice. Unfortunatelly they do not support checkboxes. How to pass it as a radio...
9
by: Frances | last post by:
Hi All, * PREMISE * I'm creating an Access form with 150 items subdivided into 20 categories. Multiple categories (and items) can be selected so my user wants checkboxes. All of the options...
1
by: Johnfcf | last post by:
I have a database consisting of 3 tables, the main table with main contact info, a second table with additional address info and a third table consisting of additional contact information, or more...
2
by: filbennett | last post by:
Hi Everyone, I'm generally unfamiliar with Access form design, but have programmed Cold Fusion applications for a couple of years. I'd like to build a data entry form in Access that allows the...
13
by: ricky.agrawal | last post by:
I'm really not sure how to go about this in Access. What I've created is a table for each location. Those tables are identical in format but different in information. The tables are named after...
22
by: mforema | last post by:
Hi everybody, I need help with a search form. I'm trying to search a table based on "Keywords" and "MajorCategories"; both criteria have their own fields in the table. The form has a "keyword"...
3
by: Salad | last post by:
Using A97, SP2, most current jet35. I have a search form. The op enters an id to search/find. If found, a data entry form is presented for that id. This form has 7 or 8 combos, a bunch of...
2
by: ebo2006 | last post by:
In the form there 16 checkboxes for types of errors a user can choose from depending on the number of errors found in one account entry. I believe putting 16 corresponding checkbox fields in the...
3
by: goldybobble | last post by:
Hello, I had an Access database that would classify items with one classification, and then classify one sub-classification based on the selection for the main classification. This worked well,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.