Divide Output from Query

juneau730

Board Regular
Joined
Jun 7, 2018
Messages
111
Morning all,

Not sure if what I am attempting to do, is doable or not, but I wasn't able to find anything.

I have a query that pulls 3 columns from the master table. Depending on what department I pull the data from, the results quantity varies.

What I would like to be able to do, if possible, is split the data into 3rds. Basically I would have 3 separate forms created from this query, with a 3rd of the data from the master table on each form.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
If you're willing to provide the code, I'm willing to give it a try and to add some data to the table
If you add a numeric (byte) field to your table (I named it AssignedTo) the code would look like:
VBA Code:
Private Sub Assign_Click()

Dim rs As Recordset
Dim strSQL As String
Dim tmpAssign As Byte
Dim tmpCount As Long

strSQL = "SELECT AssignedTo FROM YourTable " & _
         "WHERE AssignedTo = 0 OR IsNull(AssignedTo)"
Set rs = CurrentDb.OpenRecordset(strSQL)
tmpAssign = 3
tmpCount = 0

While Not rs.EOF
    If tmpAssign = 3 Then
        tmpAssign = 1
    Else
        If tmpAssign = 2 Then
            tmpAssign = 3
        Else
            tmpAssign = 2
        End If
    End If
    
    rs.Edit
    rs!AssignedTo = tmpAssign
    rs.Update
    
    tmpCount = tmpCount + 1
    
    rs.MoveNext
Wend

Set rs = Nothing
MsgBox tmpCount & " records have been assigned.", vbInformation, "Ready"

End Sub

I made a form, placed a button on it that executes the code.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top