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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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