Using sample code, crashing Access (1 Viewer)

alktrigger

Aimless Extraordinaire
Local time
Today, 07:17
Joined
Jun 9, 2009
Messages
124
Access 2007

I am busy adapting the code found in http://www.access-programmers.co.uk/forums/showthread.php?t=67164 but when I copy it to my database it crashes when it get to "Dim cnn As ADODB.connection". What is going wrong, It works when I run the sample database, but when I copy or even import the module, it puts access into an infinite error loop.

Code:
Public Function Conc(ID) As String
   Dim cnn As ADODB.Connection
   Dim rs As New ADODB.Recordset
   Dim SQL As String
   Dim sConc As String
   
   Set cnn = CurrentProject.Connection
   
'  SQL = "SELECT [Name] FROM [tblData] WHERE [Date]=#" & ID & "#"
   SQL = "SELECT [Name] FROM [tblData] WHERE [MeetingID]=" & ID
   
   rs.Open SQL, cnn, adOpenForwardOnly, adLockReadOnly
   Do While Not rs.EOF
     sConc = sConc & ", " & rs![Name]
     rs.MoveNext
   Loop
   sConc = Mid(sConc, 3)    'Remove leading comma and space.
   
   Set rs = Nothing
   Set cnn = Nothing
   
   Conc = sConc
   
End Function

Thanks ahead of time for the help
 

ezfriend

Registered User.
Local time
Today, 04:17
Joined
Nov 24, 2006
Messages
242
Did you add the ADO reference to your project?
 

Users who are viewing this thread

Top Bottom