Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:57:47+00:00 2026-06-02T22:57:47+00:00

Person Person_Pet Pet I need to make a data entry form. Let’s say we

  • 0

Person
Person_Pet
Pet

I need to make a data entry form. Let’s say we have a table called Person and that has the appropriate fields in it. On my form I need to allow the user to select from (one or many) checkboxes that represent all the possible pets they could have (fixed list of items: dog, serval, llama, jackalope, emu, dragon, spider…).

For the form, there needs to be one checkbox to represent each possible choice. If that person does have a pet dog then that checkbox needs to be true and if they don’t have a dog it needs to be false (I guess I’m stating the obvious because I got stuck trying to do this as a subform with the “many to many” and displaying “false” valued things. They can chose more than one.

Eventually I need to make a new form or reuse the data entry form for modificiations, etc.

Is this a subform? I have a Person table, Pet table, Person_Pet (id/joining) table. I’m trying to go at all this with VBA but I think I’ve picked the hard way, however, it isn’t too late to change directions.

edit:
what if i was starting with this? it would result in something that gave me a list of all possible pets and if the p.personid was null then the checkbox is not checked. if it is not null then it is checked. is this possible? (excuse the formatting, access sql writer doesn’t know what a tab is apparently and excuse sytanx errors because i had to do a quick find and replace for table names)

select pet.*, p.personid
from pet pet 
left outer join
(select pi.petID, pi.personid
from    person,
        pet_person pi,
        pet 
where   person.id = pi.personID and
        pet.id = pi.petID) as p
on p.petID = pet.id

edit:

okay. there’s a huge answer down there. i solved it, too. i haven’t looked at your answer but i will in a lil bit. here’s my answer… (no subform, just all on the main form, “person” form)

  1. make checkboxes… and name them chk1, chk2, chk3… and so on.
  2. make sure they correspond to appropriate fields in my lil pet table…. so dog = chk1, serval = chk2… stuff
  3. do this vba (and call function from Form_Current() and pass it me.id):

Function update_checkboxes(issueID As Variant)
Dim query As String
Dim rs As DAO.Recordset
Dim db As Database
Set db = CurrentDb
Dim a As String

If Not IsNull(issueID) Then
    query = "SELECT iif(joined.issueid is null, 0, 1) as binval, payer.* " & _
            "FROM payer AS payer LEFT JOIN (select ri.issueid, ri.payerid " & _
                    "from  issue i, payer r, payer_issue ri " & _
                    "where i.id = ri.issueid and r.id = ri.payerid and ri.issueid = " & issueID & _
                    ")  AS joined ON joined.payerid = payer.id;"
Else
    query = "select 0 as binval, payer.* from payer"
End If

Set rs = db.OpenRecordset(query)
rs.MoveFirst

Do While Not rs.EOF
    s = rs.Fields("CorrespondingChkboxNumber")
    Me.Controls("chk" & s).Value = rs.Fields("binval")
    rs.MoveNext
Loop

rs.Close
End Function

Yeah. that copy paste code format stackoverflow thing is hating on me. sorry. UM. issue = person, payer = pet. i know the corresponding check box thing isn’t idea, i’m going to have to search/check a string field but this shows the concept of what i think i might end up using unless……………….

Follow up question: are there any serious time constraints issues/consequences/sumthing to running these vba queries each time the record is changed?

btw. fyi. the desire to show the possible answers with selected answers is because sometimes what things aren’t is equally important as what things are. some areas/counties/municipalities won’t allow pitbulls. the whole state of california apparently outlaws ferrets. i do have a pitbull. i do not have a ferret. we all only wish we had pet dragons to train. all of these are on the no-no pet list in some areas so…. both these things need to be displayed. a listbox could do it but i feel it’s a little awkward looking. by visibly listing all my possible pets, i know which ones raise flags. although in the end it only truly matters what i do have……. still. but obviously i’m not making a cute little access database for people and pets and where they can live.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:57:48+00:00Added an answer on June 2, 2026 at 10:57 pm

    With VBA you can use the following code. There are two options:

    1. with the ‘native’ Access Listbox: this shows your selection as
      highlighted lines in a conventional listbox

      chose multiselect=1 (Single) in the listboxes property/all
      sheet and modify the below code -> uncvomment the commented lines
      and comment the ones above instead

    2. with the MSForms.Listbox (chose activeX insert in Formcreation)
      here you get the checkboxes you wanted.

      chose Multiselect:multi and ListStyle:option. Here there is no click event, so I chose the Exit event instead. I
      havent encountered any problems so far, but methodically a click
      event would be nicer.

    And here’s the code:

    Option Compare Database
    Option Explicit
    
    Dim pPetListBox As MSForms.ListBox
    
    Private Sub FillPetListbox() 
      pPetListBox.Clear
      Dim rst As DAO.Recordset
      Set rst = CurrentDb.OpenRecordset("select * from pet order by id")
      While Not rst.EOF
        pPetListBox.AddItem rst!ID
        pPetListBox.List(pPetListBox.ListCount - 1, 1) = rst!petname
        rst.MoveNext
      Wend
      rst.Close
    End Sub
    
    Private Sub Form_Current()
      Dim rst As DAO.Recordset
      Dim indx As Long
      Set rst = CurrentDb.OpenRecordset("select * from person_pet where personid=" & Me.ID)
      For indx = 0 To pPetListBox.ListCount - 1
        rst.FindFirst "petID = " & pPetListBox.Column(0, indx)
    '    rst.FindFirst "petID = " & petList.ItemData(indx)
        pPetListBox.Selected(indx) = Not rst.NoMatch
      Next
      rst.Close
    End Sub
    
    Private Sub UpdateLinkTable()
      Dim rst As DAO.Recordset
      Dim indx As Long
      Set rst = CurrentDb.OpenRecordset("select * from person_pet where personid=" & Me.ID)
      indx = pPetListBox.ListIndex
      rst.FindFirst "petID = " & pPetListBox.List(indx, 0)
      'rst.FindFirst "petID = " & petList.ItemData(indx)
      If (pPetListBox.Selected(indx) And rst.NoMatch) Then
        rst.AddNew
        rst!personID = Me.ID
        rst!petID = pPetListBox.Column(0, indx)
        rst.Update
      Else
        If ((Not pPetListBox.Selected(indx)) And (Not rst.NoMatch)) Then
          rst.Delete
        End If
      End If
      rst.Close
    End Sub
    
    Private Sub Form_Load()
      Set pPetListBox = Me.msfPetListBox.Object
      FillPetListbox
    End Sub
    
    Private Sub msfPetListBox_Exit(Cancel As Integer)
    'Private Sub petList_Click()
      UpdateLinkTable
    End Sub
    

    If you use the native access listbox you dont have to load the listbox content programmatically (FillPetListBox). Instead you can just set the rowsource-property to the pet-table. I think it is even possible to bind the MSForms.listbox to that table – but I didn’t try it out (yet).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a table people and a table pets and I'd like
Say you have these two methods: Number 1: void AddPerson(Person person) { // Validate
I have a data structure Person struct Person { protected: string name; int age;
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have an excel column that looks like this: Person 1, Person 2 Person
I have a simple @OneToMany between Person and Pet entities: @OneToMany(mappedBy=owner, cascade=CascadeType.ALL, fetch=FetchType.EAGER) public
I have a strongly typed Person view, that I want to render a partial
I've got an SQL table that stores a person record where one column is
Lets say I have an object class Person { public string Name { get;
I have an interface Person and I have 2 classes Female and Male that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.