Why there is an error in my Sub in VBA

R

rslowin

I have three tables

TStudents ( idStudent PK, Name, Languages )
TALanguagesStudents( idStudent, idLanguage )
TLanguages ( idLanguage PK, Language)

I need to concatenate all languages known by a Student in
a field TStudents.Languages

Here is code in VBA

Sub pre()

Dim dbs As Database
Dim rst, rst0, rst1 As Recordset
Dim ids, idl, str_pom As String

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("TStudents")
With rst
..MoveFirst
While Not .EOF
str_pom = ""
ids = !idStudent
Set rst0 = dbs.OpenRecordset("SELECT * FROM
TALanguagesStudents WHERE idStudent = " & Trim(Str(ids)))
With rst0
..MoveFirst
While Not .EOF
idl = !idLanguage
Set rst1 = dbs.OpenRecordset("SELECT TLanguages.Language
FROM TLanguages INNER JOIN TALanguagesStudents ON
TLanguages.idLanguage = TALanguagesStudents.idLanguage
WHERE (((TALanguageStudents.idStudent)=" & Trim(Str(ids))
& ") AND ((TALanguageStudents.idLanguage)=" & Trim(Str
(idl)) & "))")
str_pom = str_pom + " " + rst1!Language
..MoveNext
Wend
End With
..Edit
!Languages = str_pom
..Update
..MoveNext
Wend
End With

End Sub

The problem is in a line Set rst1 = dbs......

An error #13 Type mismatch

Can you help me, please.

Regards

Rafi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top