Thank you for your time to reply.
I have been working on it and I have a solution. Since the main list of possible interest areas must be flexible as they add or remove areas to volunteer in, I have my tables setup like I said. Interest Areas Table | Volunteer Interest Table | Volunteer Table
I have a button that triggers my code which goes to the database, grabs the items in the Interest Areas table, loops through them. Opens a blank (save for 2 buttons) form and generates the checkboxes. It can hold up to about 20 with the size window I have now. As it creates these, it runs a dlookup to see if the volunteerID (passed and stored in a generated hidden text field) has an entry in the middle table that joins the 2. If so, it checks it, if not, it leaves it blank.
The update process is not too bad either. Since the checks are dynamically generated I named them check_X where X is the number of the interest ID. When the update button is clicked, it deletes all entries from the middle table that exist for this user, and then adds the new ones back in.
It is really not a bad process. 1 form, and a couple of subs. In case anyone is looking to do this kind of thing, here is the code I used. If anyone can show me improvements in the coding, then please do.
Click button that says Edit Interests -> the misspelled click procedure runs.
Code:
Private Sub viewIntersts_Click()
DoCmd.OpenForm "frmInterestsSubform", acDesign
createInterestControls (ID)
DoCmd.OpenForm "frmInterestsSubform", acNormal
End Sub
Private Function createInterestControls(volunteerID)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sqlStr As String
Set db = CurrentDb
Dim i As Long
Dim col As Long
Set rs = db.OpenRecordset("SELECT tblVolunteerInterestAreas.interestID, tblVolunteerInterestAreas.interestName, tblVolunteerInterestAreas.interestDescription FROM tblVolunteerInterestAreas ORDER BY tblVolunteerInterestAreas.[interestName]")
If (rs.RecordCount <> 0) Then
i = 1
Dim ctrl_i As Control
col = 1
x = 0
y = 0
leftStart = 200
topStart = 200
leftOffset = 1300
topOffset = 300
Set volunteerIDField = CreateControl("frmInterestsSubform", acTextBox, acDetail, , , 5000, 50, 500, 300)
volunteerIDField.Name = "volunteerID"
volunteerIDField.DefaultValue = volunteerID
volunteerIDField.Visible = False
Do While Not rs.EOF
thisInterestID = rs.Fields("interestID").Value
thisInterestName = rs.Fields("interestName").Value
' start a new column
If i > (col * 10) Then
col = col + 1
x = 0
y = y + 1
End If
Set ctrl_i = CreateControl("frmInterestsSubform", acCheckBox, acDetail, , , leftStart + ((leftOffset * y) * col), topStart + (topOffset * x), 175, 175)
ctrl_i.Name = "check_" & thisInterestID
Set label_i = CreateControl("frmInterestsSubform", acLabel, acDetail, "check_" & thisInterestID, , leftStart + ((leftOffset * y) * col) + 200, topStart + (topOffset * x) - 50, 2500, 235)
label_i.Caption = thisInterestName
label_i.FontWeight = 700
If Not IsNull(DLookup("ID", "tblVolunteerInterests", "volunteerID = " & ID & " AND interestID = " & thisInterestID)) Then
ctrl_i.DefaultValue = True
Else
ctrl_i.DefaultValue = False
End If
rs.MoveNext
i = i + 1
x = x + 1
Loop
End If
End Function
Which creates this form.....
Click the update button and then to process.....
Code:
Private Sub updateInterests_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sqlStr As String
Set db = CurrentDb
Dim theFieldName As String
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE FROM tblVolunteerInterests WHERE volunteerID = " & volunteerID
DoCmd.SetWarnings True
Set rs = db.OpenRecordset("SELECT tblVolunteerInterestAreas.interestID, tblVolunteerInterestAreas.interestName, tblVolunteerInterestAreas.interestDescription FROM tblVolunteerInterestAreas ORDER BY tblVolunteerInterestAreas.[interestName]")
If (rs.RecordCount <> 0) Then
Do While Not rs.EOF
ID = rs.Fields("interestID").Value
If Me.Controls("check_" & ID) Then
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tblVolunteerInterests (volunteerID, interestID) Values (" & volunteerID & ", " & ID & "); "
DoCmd.SetWarnings True
End If
rs.MoveNext
Loop
End If
Forms!Volunteers!volInterestsListbox.Requery
DoCmd.Close , , acSaveNo
End Sub
Likely very sloppy, but it works and does exactly what I want. A dynamic check box list that allows users to choose from them.
Thanks,
nate