Hi Bruce,
Hope you're stay here is going well and you didn't get groped too
invasably (is this a word??) by the TSA (lol).
update; the query worked without issue (at least the initial one- via
the one originating sheet). Of course, the client didn't specify that
more information was needed (based on other worksheets within the
workbook). Rather than add more SQL garble to the on-change event of
the combo box, I chose instead to call additional functions after the
initial query was put in place- worked like a charm! (example code
below)
<code>
Public Sub ComboBox1_Change()
'On change event of the ComboBox initiates the first query for
regional information based on the alumni dashboard
'worksheet. After completing the first query, the procedure hands off
to the next function which runs the second
'query and so on. We pass in the ContType as an argument to preceeding
function.
'variables
Dim strSQL As String, cnn As String, ContType As String
'set connection string variable
cnn = "ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName &
";DefaultDir=" _
& ThisWorkbook.Path & _
";DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
'set ContType variable to city based on index selected; add one
last entry
'in city list of user defined- open up message box and use that
input for the lookup variable
Select Case ComboBox1.ListIndex
Case 0: Exit Sub
Case 1: ContType = "Alabama"
Case 2: ContType = "Austin"
Case 3: ContType = "Baltimore"
Case 4: ContType = "Bay Area"
Case 5: ContType = "Charlotte"
Case 6: ContType = "Chicago"
Case 7: ContType = "Colorado"
Case 8: ContType = "Connecticut"
Case 9: ContType = "D.C. Region"
Case 10: ContType = "Dallas-Fort Worth"
Case 11: ContType = "Detroit"
Case 12: ContType = "Eastern North Carolina"
Case 13: ContType = "Greater Boston"
Case 14: ContType = "Greater Nashville"
Case 15: ContType = "Greater New Orleans"
Case 16: ContType = "Greater Newark"
Case 17: ContType = "Hawaii"
Case 18: ContType = "Houston"
Case 19: ContType = "Indianapolis"
Case 20: ContType = "Jacksonville"
Case 21: ContType = "Kansas City"
Case 22: ContType = "Las Vegas Valley"
Case 23: ContType = "Los Angeles"
Case 24: ContType = "Memphis"
Case 25: ContType = "Metro Atlanta"
Case 26: ContType = "Miami-Dade"
Case 27: ContType = "Mid-Atlantic"
Case 28: ContType = "Milwaukee"
Case 29: ContType = "Mississippi Delta"
Case 30: ContType = "New Mexico"
Case 31: ContType = "New York"
Case 32: ContType = "Oklahoma"
Case 33: ContType = "Phoenix"
Case 34: ContType = "Rhode Island"
Case 35: ContType = "Rio Grande Valley"
Case 36: ContType = "San Antonio"
Case 37: ContType = "South Dakota"
Case 38: ContType = "South Louisiana"
Case 39: ContType = "St. Louis"
Case 40: ContType = "Twin Cities"
Case 41: ContType = Application.InputBox("Enter the Region's
Name:", "User-Defined Region")
End Select
'Sql statements for the first query
strSQL = "select [Alumni Dashboard$].person_id, [Alumni Dashboard
$].firstname, [Alumni Dashboard$].lastname,"
strSQL = strSQL & "[Alumni Dashboard$].corps_last_name, [Alumni
Dashboard$].corps_region, [Alumni Dashboard$].alum_region,"
strSQL = strSQL & "[Alumni Dashboard$].alum_region_override,
[Alumni Dashboard$].person_type, [Alumni Dashboard$].corps_year,"
strSQL = strSQL & "[Alumni Dashboard$].poc, [Alumni Dashboard
$].gender, [Alumni Dashboard$].ethnicity,"
strSQL = strSQL & "[Alumni Dashboard$].email, [Alumni Dashboard
$].address1, [Alumni Dashboard$].address2,"
strSQL = strSQL & "[Alumni Dashboard$].city, [Alumni Dashboard
$].state, [Alumni Dashboard$].zip,"
strSQL = strSQL & "[Alumni Dashboard$].homephone, [Alumni Dashboard
$].mobile, [Alumni Dashboard$].workphone,"
strSQL = strSQL & "[Alumni Dashboard$].empl_profession, [Alumni
Dashboard$].empl_role, [Alumni Dashboard$].empl_field,"
strSQL = strSQL & "[Alumni Dashboard$].empl_level, [Alumni
Dashboard$].empl_title, [Alumni Dashboard$].empl_employer,"
strSQL = strSQL & "[Alumni Dashboard$].empl_school_or_division,
[Alumni Dashboard$].empl_school_type, [Alumni Dashboard
$].empl_placement_status,"
strSQL = strSQL & "[Alumni Dashboard$].empl_start, [Alumni
Dashboard$].Graduate_Degree, [Alumni Dashboard
$].Graduate_Field_Of_Study,"
strSQL = strSQL & "[Alumni Dashboard$].University, [Alumni
Dashboard$].pli_active_pipeline, [Alumni Dashboard
$].pli_declared_this_fy,"
strSQL = strSQL & "[Alumni Dashboard$].pli_current_declared,
[Alumni Dashboard$].pli_current_elected, [Alumni Dashboard
$].pli_past_elected,"
strSQL = strSQL & "[Alumni Dashboard
$].pli_past_unsuccessful_candidate, [Alumni Dashboard
$].pli_departure_flag, [Alumni Dashboard$].pli_pipeline_status,"
strSQL = strSQL & "[Alumni Dashboard$].pli_race_result, [Alumni
Dashboard$].pli_candidate_office, [Alumni Dashboard
$].pli_filing_deadline,"
strSQL = strSQL & "[Alumni Dashboard$].pli_declared_date, [Alumni
Dashboard$].pli_election_date, [Alumni Dashboard$].pli_office_status,"
strSQL = strSQL & "[Alumni Dashboard$].pli_office_start_date,
[Alumni Dashboard$].pli_office_name, [Alumni Dashboard
$].pli_office_type,"
strSQL = strSQL & "[Alumni Dashboard$].pli_departure_status,
[Alumni Dashboard$].running_for_office_interest, [Alumni Dashboard
$].interest_timeframe,"
strSQL = strSQL & "[Alumni Dashboard$].pli_campaign_trainings,
[Alumni Dashboard$].political_activist, [Alumni Dashboard
$].policy_interest,"
strSQL = strSQL & "[Alumni Dashboard$].pli_lee_mem, [Alumni
Dashboard$].pli_lee_join_date, [Alumni Dashboard
$].pli_webinar_registrant,"
strSQL = strSQL & "[Alumni Dashboard$].pli_webinar_attendee,
[Alumni Dashboard$].pli_newsblast_subsc, [Alumni Dashboard
$].pli_num_events,"
strSQL = strSQL & "[Alumni Dashboard$].pli_fellowships, [Alumni
Dashboard$].pli_fellowships_incomplete, [Alumni Dashboard
$].pli_int_pts,"
strSQL = strSQL & "[Alumni Dashboard$].pli_int_pts_cmts, [Alumni
Dashboard$].pli_exp_pts, [Alumni Dashboard$].pli_exp_pts_cmts,"
strSQL = strSQL & "[Alumni Dashboard$].leadership_interest,
[Alumni Dashboard$].leadership_interest_level, [Alumni Dashboard
$].current_year_money,"
strSQL = strSQL & "[Alumni Dashboard
$].current_year_qualified_time, [Alumni Dashboard$].current_year_time,
[Alumni Dashboard$].fy10_money,"
strSQL = strSQL & "[Alumni Dashboard$].Willing_to_share_info,
[Alumni Dashboard$].LEE_member, [Alumni Dashboard
$].Not_member_and_willing_to_share,"
strSQL = strSQL & "[Alumni Dashboard$].Declared from [Alumni
Dashboard$]"
strSQL = strSQL & " where [Alumni Dashboard$].alum_region = '" &
ContType & "'"
strSQL = strSQL & " order by [Alumni Dashboard$].alum_region,
[Alumni Dashboard$].lastname"
'Place the extracted information on the Region sheet; clear out
any information that was there first and
'populate it with the data from the SQL statement
[regional!a1].CurrentRegion.Clear
With [Sheet20].QueryTables.Add(Connection:=cnn,
Destination:=[regional!a1], Sql:=strSQL)
.Refresh False
.Delete
End With
'call the function to run the second query
getDataOne (ContType)
'call the function to run the third query
getDataTwo (ContType)
'call the function to run the fourth query
getDataThree (ContType)
'call the function to run the fourth query
getDataFour (ContType)
'call the function to run the fourth query
getDataFive (ContType)
End Sub
Public Function getDataOne(ContType As String)
'Function that runs the region query against the Group Meeting sheet;
we pass
'in the combo box selection as a string variable based on the users
selection
'variables
Dim strSQL As String, cnn As String
'set up the connection string
cnn = "ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName &
";DefaultDir=" _
& ThisWorkbook.Path & _
";DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
'sql statements for second query
strSQL = "select [Group Meetings$].alum_region, [Group Meetings
$].personid, [Group Meetings$].firstname,"
strSQL = strSQL & "[Group Meetings$].lastname, [Group Meetings
$].corps_year, [Group Meetings$].account,"
strSQL = strSQL & "[Group Meetings$].startdate, [Group Meetings
$].description, [Group Meetings$].meeting_topics,"
strSQL = strSQL & "[Group Meetings$].politics_policy, [Group
Meetings$].notes, [Group Meetings
$].active_talent_recruitment_activity,"
strSQL = strSQL & "[Group Meetings$].userid from [Group Meetings
$]"
strSQL = strSQL & " where [Group Meetings$].alum_region = '" &
ContType & "'"
strSQL = strSQL & " order by [Group Meetings$].alum_region, [Group
Meetings$].lastname"
'place the results in Regional2 worksheet
[regional2!a1].CurrentRegion.Clear
With [Sheet21].QueryTables.Add(Connection:=cnn,
Destination:=[regional2!a1], Sql:=strSQL)
.Refresh False
.Delete
End With
End Function
Public Function getDataTwo(ContType As String)
'Function that runs the region query against the Training sheet; we
pass
'in the combo box selection as a string variable based on the users
selection
'variables
Dim strSQL As String, cnn As String
'set up the connection string
cnn = "ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName &
";DefaultDir=" _
& ThisWorkbook.Path & _
";DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
'sql statements for third query
strSQL = "select [Trainings$].alum_region, [Trainings$].personid,
[Trainings$].training_regions,"
strSQL = strSQL & "[Trainings$].firstname, [Trainings$].lastname,
[Trainings$].program_one,"
strSQL = strSQL & "[Trainings$].rock, [Trainings$].m_f, [Trainings
$].poc,"
strSQL = strSQL & "[Trainings$].ethnicity, [Trainings
$].program_start, [Trainings$].program_end,"
strSQL = strSQL & "[Trainings$].training_fellowship, [Trainings
$].training,"
strSQL = strSQL & "[Trainings$].type_of_training from [Trainings
$]"
strSQL = strSQL & " where [Trainings$].alum_region = '" & ContType
& "'"
strSQL = strSQL & " order by [Trainings$].alum_region, [Trainings
$].lastname"
'place the results in Regional3 worksheet
[regional3!a1].CurrentRegion.Clear
With [Sheet22].QueryTables.Add(Connection:=cnn,
Destination:=[regional3!a1], Sql:=strSQL)
.Refresh False
.Delete
End With
End Function
Public Function getDataThree(ContType As String)
'Function that runs the region query against the Fellowship sheet; we
pass
'in the combo box selection as a string variable based on the users
selection
'variables
Dim strSQL As String, cnn As String
'set up the connection string
cnn = "ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName &
";DefaultDir=" _
& ThisWorkbook.Path & _
";DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
'sql statements for fourth query
strSQL = "select [Fellowship$].region, [Fellowship$].regions,
[Fellowship$].personid,"
strSQL = strSQL & "[Fellowship$].firstname, [Fellowship
$].lastname, [Fellowship$].program_one,"
strSQL = strSQL & "[Fellowship$].LEE_fellowship, [Fellowship
$].m_f, [Fellowship$].poc,"
strSQL = strSQL & "[Fellowship$].ethnicity, [Fellowship
$].program_start, [Fellowship$].program_end,"
strSQL = strSQL & "[Fellowship$].training_fellowship, [Fellowship
$].early_stage, [Fellowship$].mid_career,"
strSQL = strSQL & "[Fellowship$].advanced from [Fellowship$]"
strSQL = strSQL & " where [Fellowship$].region = '" & ContType &
"'"
strSQL = strSQL & " order by [Fellowship$].region, [Fellowship
$].lastname"
'place the results in Regional4 worksheet
[regional4!a1].CurrentRegion.Clear
With [Sheet23].QueryTables.Add(Connection:=cnn,
Destination:=[regional4!a1], Sql:=strSQL)
.Refresh False
.Delete
End With
End Function
Public Function getDataFour(ContType As String)
'Function that runs the region query against the LEE Watchlist sheet;
we pass
'in the combo box selection as a string variable based on the users
selection
'variables
Dim strSQL As String, cnn As String
'set up the connection string
cnn = "ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName &
";DefaultDir=" _
& ThisWorkbook.Path & _
";DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
'sql statements for fifth query
strSQL = "select [LEE Watchlist$].alum_region, [LEE Watchlist
$].pid, [LEE Watchlist$].firstname,"
strSQL = strSQL & "[LEE Watchlist$].lastname, [LEE Watchlist
$].poc_within_LEE_staff, [LEE Watchlist$].database_pipeline_status,"
strSQL = strSQL & "[LEE Watchlist$].actual_pipeline_status, [LEE
Watchlist$].optional_potential_seat_office, [LEE Watchlist
$].declared_intent,"
strSQL = strSQL & "[LEE Watchlist$].candidate_filed, [LEE Watchlist
$].filing_date, [LEE Watchlist$].election_date,"
strSQL = strSQL & "[LEE Watchlist$].fundraising_target, [LEE
Watchlist$].money_raised, [LEE Watchlist$].cash_on_hand,"
strSQL = strSQL & "[LEE Watchlist$].individual_contribution_limit,
[LEE Watchlist$].no_of_vol_supporters_working_for_candidate,"
strSQL = strSQL & "[LEE Watchlist$].google_doc_link from [LEE
Watchlist$]"
strSQL = strSQL & " where [LEE Watchlist$].alum_region = '" &
ContType & "'"
strSQL = strSQL & " order by [LEE Watchlist$].alum_region, [LEE
Watchlist$].lastname"
'place the results in Regional5 worksheet
[regional5!a1].CurrentRegion.Clear
With [Sheet24].QueryTables.Add(Connection:=cnn,
Destination:=[regional5!a1], Sql:=strSQL)
.Refresh False
.Delete
End With
End Function
Public Function getDataFive(ContType As String)
'Function that runs the region query against the PALI Dashboard sheet;
we pass
'in the combo box selection as a string variable based on the users
selection
'variables
Dim strSQL As String, cnn As String
'set up the connection string
cnn = "ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName &
";DefaultDir=" _
& ThisWorkbook.Path & _
";DriverId=790;MaxBufferSize=2048;PageTimeout=5;"
'sql statements for sixth query
strSQL = "select [PALI Dashboard$].alum_region, [PALI Dashboard
$].personid, [PALI Dashboard$].firstname,"
strSQL = strSQL & "[PALI Dashboard$].lastname, [PALI Dashboard
$].cy, [PALI Dashboard$].cr,"
strSQL = strSQL & "[PALI Dashboard$].ethnicity, [PALI Dashboard
$].poc, [PALI Dashboard$].email,"
strSQL = strSQL & "[PALI Dashboard$].profession, [PALI Dashboard
$].role, [PALI Dashboard$].field,"
strSQL = strSQL & "[PALI Dashboard$].employer, [PALI Dashboard
$].title, [PALI Dashboard$].pre_survey_exp_bucket_021511, [PALI
Dashboard$].bucket_final,"
strSQL = strSQL & "[PALI Dashboard
$].policy_interest_from_alumni_survey, [PALI Dashboard
$].comm_org_interest_from_alumni_survey,"
strSQL = strSQL & "[PALI Dashboard$].type_of_leader, [PALI
Dashboard$].b2_b3_bx_by_and_actively_pursuing, [PALI Dashboard
$].b3_and_p,"
strSQL = strSQL & "[PALI Dashboard$].b3_and_a_or_o from [PALI
Dashboard$]"
strSQL = strSQL & " where [PALI Dashboard$].alum_region = '" &
ContType & "'"
strSQL = strSQL & " order by [PALI Dashboard$].alum_region, [PALI
Dashboard$].lastname"
'place the results in Regional6 worksheet
[regional6!a1].CurrentRegion.Clear
With [Sheet25].QueryTables.Add(Connection:=cnn,
Destination:=[regional6!a1], Sql:=strSQL)
.Refresh False
.Delete
End With
End Function
</code>
Originally, I tested trying to run the code within the same on change
event, but variable issues caused problems so I broke it into seperate
modules and the queries ran fine.
~Allen
On Aug 15, 9:08 pm, bruce mcpherson <
br...@mcpher.com> wrote:
> Hi Allen
>
> Hi Allen
>
> Glad you got it going.. I think you may need to revisit though if this is
> supposed to be interactive - Excel quickly goes down the toilet with a lot
> of data. Let me know how it works out.
>
> I'm in US for the week actually - going back to UK on saturday
>
> bruce
>
> ...
>
> read more »