Hoi, hoe kan ik met VBA vanuit één tabel gegevens uit een andere tabel ophalen? Tussen Lid.ID en Pay.PayID bestaat een relatie. Wat ik voorlopig wil doen is het totaal van de Pay-records per lid stockeren in een variabele. Weet iemand hoe dit zou kunnen? Dank bij voorbaat. Met onderstaande code krijg ik steeds Run-time error '2342': A RunSQL action requires an argument consisting of an SQL statement. Blijkbaar deugt de rode regel niet.
Option Compare Database
Option Explicit
Private Sub nazicht()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim totaal As Double
Dim strNr As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(Name:="Lid", Type:=dbOpenTable)
With rst.MoveFirstEnd With
Do While Not .EOF
strNr = Trim(![ID])Loop
DoCmd.SetWarnings False
strSQL = "SELECT sum(Pay.PayBedrag) as totaal FROM Pay WHERE Pay.PayID = " & strNr & ";"
DoCmd.RunSQL (strSQL)
MsgBox totaal
.MoveNext
End Sub