I have a form with a combo box and button that creates tables based on a group of records by a variable name of a value in a field. The combo box holds the values and the button executes the code below. This all works fine, however I need a button for when the list is long in the combo box to run all instances of possible tables (I still need the single run feature).
This is where it all goes south. I have tried a For Each statemtent but I usually don't ever get that far with VB in MS Access. Here is a sample of the code that works and an unfinished sample of something I came up with to try a run all button. I appreciate andy help.
Working-
Private Sub Command2_Click()
Dim strSQL As String
Dim strSourceSelected As String
strSourceSelected = Trim$(Me![Combo5])
strSQL = "SELECT Split.* INTO " & strSourceSelected
strSQL = strSQL & " FROM Split"
strSQL = strSQL & " WHERE Split.Field4 = [Forms]![Create_Split]![Combo5]"
DoCmd.RunSQL strSQL
End Sub
Not Working-
Private Sub Command2_Click()
Dim strSQL As String
Dim strSourceSelected As String
Dim strSourceSelected2 As Variant
Dim strSourceSelected3 As Variant
strSourceSelected = Trim$(Me![Combo5])
strSourceSelected2 = Trim$(Me![Combo5])
strSourceSelected3 = "Select Field4 From Market_Distinct"
For Each strSourceSelected2 In strSourceSelected3
strSQL = "SELECT Market.* INTO " & strSourceSelected
strSQL = strSQL & " FROM Market"
strSQL = strSQL & " WHERE Market.Field4 = strSourceSelected"
DoCmd.RunSQL strSQL
Next
End Sub
--
Message posted via http://www.accessmonster.com