Morning all,
I am trying to create a function that will populate one table with items of another, based on the tables ID number.
For example:
There are 4 classes, each one has 10 subjects, there are only 30 subjects in total though, so some of these subjects are shared.
I'm trying to create a selection list with each of the classes in it, that will then allow the user to select that class and populate a table with the appropiate subjects in it.
SQL Example:
Hopefully that makes sense?
Anyway, I have the following code in my function
But when I try and run the loop to make sure it's getting data from my array, I get this:
Now I'm fairly certain that I have created both my Array and my Loop in a really bad way! No matter what I have tried, I've not been able to get it working correctly.
So... any ideas?
I am trying to create a function that will populate one table with items of another, based on the tables ID number.
For example:
There are 4 classes, each one has 10 subjects, there are only 30 subjects in total though, so some of these subjects are shared.
I'm trying to create a selection list with each of the classes in it, that will then allow the user to select that class and populate a table with the appropiate subjects in it.
SQL Example:
Code:
SELECT CompID FROM ClassesCompetencies WHERE ClassID = MyDropDownList
Hopefully that makes sense?
Anyway, I have the following code in my function
Code:
Function addComps()
DoCmd.SetWarnings False
Dim strCompID As String
Dim strPicNo As String
Dim strSQL As String
' assign two variables to our CompID and PicNo
strClassID = Me.ClassListCombo.Value
strPicNo = Me.PicNo.Value
' count how many rows in the table ClassesCompetencies where ClassID is Me.ClassListCombo.Value
Dim xRows As Long
' select CompID FROM Classes Competencies where ClassID = strClassID
xRows = DCount("[CompID]", "ClassesCompetencies", "[ClassID]=" & strClassID & "")
' define the array based on how many rows in the table as above
Dim myArray(xRows) As String
' insert data into the array
strSQL = "INSERT INTO myArray(xRows) ([CompID]) SELECT [CompID] FROM ClassesCompetencies WHERE [ClassID] =" & strClassID
Dim xArray As Variant
xArray = 0
For Each xArray In myArray()
MsgBox xArray
Next xArray
'myArray = add all CompID records from ClassesCompetencies where ClassID equals the value from the combo box.
Me.Refresh
DoCmd.SetWarnings True
End Function
But when I try and run the loop to make sure it's getting data from my array, I get this:
Code:
Run-time error '92':
For loop not initialised
Now I'm fairly certain that I have created both my Array and my Loop in a really bad way! No matter what I have tried, I've not been able to get it working correctly.
So... any ideas?