I got en error while opening my form in access.
This code should be executed with the "OnOpen event" for that form.
But im getting an error in my script.
Dim ThisDB As DAO.Database
Set ThisDB = CurrentDb
Dim d As DAO.Recordset
Dim q As String
q = "SELECT [tbl-apartner].[EMail] FROM [tbl-apartner] WHERE [tbl-apartner].[SID] = " & sid2 'sql query
Set d = ThisDB.OpenRecordset(q, dbOpenDynaset)
Dim Result As String
Result = ""
If d.EOF = False Or d.BOF = False Then 'if-else clause
d.MoveFirst
Do While Not d.EOF
If Result <> "" Then Result = Result & "; "
Result = Result & d!EMail
d.MoveNext
Loop
End If
d.Close
The faulty line is:
Set d = ThisDB.OpenRecordset(q, dbOpenDynaset)
debug.print q
before the openrecordset. My guess is that yoursid2
is NULL – Thomas GMsgBox q
and the sid2 is not NULL. the output ofMsgBox q
isSELECT [tbl-apartner].[EMail] FROM [tbl-apartner] WHERE [tbl-apartner].[SID] = AKP
– rel0aded0ne