Solved Check box on continuous form - affects all rows

Local time
Today, 06:04
Joined
Dec 10, 2024
Messages
70
Hi,
I have a form where I can choose a customer, and then a subform displays all jobs currently set to "For Delivery"
I have added a control on the subform which is an unbound yes/no check box.
A query then looks at this check box status to decide whether to include this item on the delivery note.
The check box works to a point, when unticked it doesn't show on the report, and when ticked it does.
The issue im having is when I tick one row, it ticks all rows. It seems a simple mistake somewhere but can't figure out why its doing this.

Could anyone help?
 

Attachments

  • subform.png
    subform.png
    11.4 KB · Views: 10
Last edited:
I believe the issue is because its unbound. Do I need to add a field to the job table and bind the control to this?
I didn't really want to store this in a table as its just temporary one off when running the report
 
Have you tried a query and add the field to that?

You would be correct I believe?
 
Perhaps this is what you are looking for?
 
Like Duane, I'd suggest that you open a dialogue form containing a multi select list box, whose RowSource restricts the rows returned to those which reference the parent form's key used as the subforms LinkMasterFields property. The following is an example of the sort of code in the dialogue form's module to open a report:

Code:
Private Sub cmdOpenReport_Click()

    Dim varItem As Variant
    Dim strWhereClause As String
    Dim ctrl As Control
   
    Set ctrl = Me.lstContacts
   
    If ctrl.ItemsSelected.Count > 0 Then
        ' if at least one item has been selected in the list box
        ' loop through the control's ItemsSelected collection
        ' and build a value list of ContactID values
        For Each varItem In ctrl.ItemsSelected
            strWhereClause = strWhereClause & " OR Contacts.ContactID = " & ctrl.ItemData(varItem)
        Next varItem
       
        ' build WHERE clause for report's query
        strWhereClause = " WHERE " & Mid(strWhereClause, 5)
        ' open report in print preview, passing WHERE clause into report
        DoCmd.OpenReport "rptContacts", View:=acViewPreview, OpenArgs:=strWhereClause
    Else
        MsgBox "No contacts selected", vbInformation, "Warning"
    End If

End Sub

The code builds a value list of the selected values from the list box's BoundColumn, in this case the hidden ContactID column, and passes the list to to the report as the OpenArgs argument of the OpenReport method. A WHERE clause is then added to the report's RecordSource query in the report's Open event procedure:

Code:
Private Sub Report_Open(Cancel As Integer)

    ' add WHERE clause to report's query
    Me.RecordSource = Replace(Me.RecordSource, ";", "") & Me.OpenArgs & ";"
   
End Sub

This assumes that the report's RecordSource query is not already restricted by a WHERE or HAVING clause. If the query is already restricted by a WHERE clause then it would be a simple matter to amend the code which opens the report so that the OpenArgs argument begins with AND rather than WHERE. If the query aggregates data on the other hand and is restricted by a HAVING clause, then it would be trickier, as the WHERE clause would have to be inserted into the query before the HAVING clause. In that case there are other methods which could be used, referencing a hidden control in the form as a parameter.

If you want to stick with a check box, however, then the simple solution is to add a Boolean column to the relevant table, and restrict the report on that column. In the parent form's Current event procedure execute an UPDATE statement to set the Boolean column to FALSE in every row.
 

There are several different approaches here.
 
true"]https:/ww.access-programmers.co.uk/forums/threads/a-multi-select-form-using-unbound-check-boxes.323395/[/URL]

Thanks, this worked great.

The only bit that got me was the setfocus to "GF" line of code. Turns out "GF" was a text box but was 0cm x 0cm so couldn't see it anywhere but it wasn't hidden.
I added one and it worked great.
 
yes it's 0 x 0cm so cannot be seen - but needs the visible property as true to be able to receive the focus. It's a method I use when I need to do something to a control that has the focus - simply move the focus elsewhere. GF is just a name which means 'Got Focus' or 'Gets Focus'.
 

Users who are viewing this thread

Back
Top Bottom