changing comboboxs on form open

dhannant

New Member
Joined
Oct 2, 2014
Messages
10
So I have a form that is used through 4 different sections of my work center. It's used to create schedules and each combox is populated using information that is in the data via Select [Combined Roster].[Last Name] etc... that parts not important because it works great. My problem is that since a single form is used for all 4 sections, and each section has about 30 people, I don't want to populate the list with EVERYONEs name. Is it's broken down at the end with the WHERE [section]='sales' or 'marketing' etc...

Every section can access it through a menu and is populated differently depending on which section they are in. So if a sales manager pulls up the scheduler, it's populated only with his sales reps and like wise for the warehouse manager being populated with only warehouse workers. There are 15 comboboxes for day shift labeled Days1 - Days15.

Initially I just set it up like


Code:
Forms![Shift Schedules]!Days2.RowSource = "SELECT [Roster].[Last Name] & ', ' & Left([First Name],1) FROM [Roster] WHERE [Work Center]='Sales'; "
Forms![Shift Schedules]!Days3.RowSource = "SELECT [Roster].[Last Name] & ', ' & Left([First Name],1) FROM [Roster] WHERE [Work Center]='Sales'; "
Forms![Shift Schedules]!Days4.RowSource = "SELECT [Roster].[Last Name] & ', ' & Left([First Name],1) FROM [Roster] WHERE [Work Center]='Sales'; "

This works fine however, I have 3 shifts so that's 45 lines like the above and it's just a mess. Would rather do it with a while loop. So I set this up.

Code:
Dim formsource As Variant
Dim cbooutput As String
Dim cbovalue As Integer
Dim cboexp As Variant

cbovalue = 2

Do
    cbooutput = "Days" & cbovalue
    formsource = "Forms![Shift Schedules]!"
    cboexp = formsource & cbooutput
    cboexp.rowsource = "SELECT [Roster].[Last Name] & ', ' & Left([First Name],1) FROM [Roster] WHERE [Work Center]='Sales'; "
    cbovalue = cbovalue + 1
    
    Debug.Print cbooutput
    Debug.Print cboexp
    Debug.Print formsource
    Debug.Print cbovalue
    
Loop Until cbovalue > 16

All of the variables work... I can see in the watch window that it's all set to what it should be however, it's like it's not combining everything correctly because unlike the 1st part, none of the RowSource information changes on the shift schedule. Maybe I'm using the variables in the statement incorrectly? I'm not sure.

The cboexp is supposed Forms![Shift Schedules]!Days1.RowSource = "SELECT [Roster].[Last Name] & ', ' & Left([First Name],1) FROM [Roster] WHERE [Work Center]='Sales';"
Abvously the only part that actually changes is the Days1... Is there an easier way or am I on the right path?

New to variables and Loops.

Thanks,
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
ok... so I was way wrongloop setup. Even if I was able to make that work, which I doubt, I found a much easier way to do this through a lot of trial and error. Just posting incase someone else has a similar question.

Code:
Dim ctrl As Access.Control
For Each ctrl In Forms![Shift Schedules].Controls
    If ctrl.ControlType = acComboBox Then
       ctrl.RowSource = "SELECT [Roster].[Last Name] & ', ' & Left([First Name],1) FROM [Roster] WHERE [Work Center]='Sales'; "   
    End If
Next ctrl
 
Upvote 0

Forum statistics

Threads
1,221,869
Messages
6,162,530
Members
451,773
Latest member
ssmith04

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