Hi Experts;
I have an issue about VBA functions in Access. I am using a code to define function "Concatenate".
I am using this code with a textbox. If you use Concatenate function in textbox like this,
Code:
=Concatenate("Select Supp_Series FROM Supplier")
the Code retrieves the Supp_Series from Supplier table and put them in textbox seperated with (-).
But İf you use a SQL statement like below, it gives error.
Code:
=Concatenate("Select Supp_Series FROM Supplier WHERE [Forms]![Form1]!Combo10")
What is the problem ? Why we cannot link a value in Form ? How we should amend the code.
And this is the Concatanate function code that lives in a module.
Code:
Function Concatenate(pstrSQL As String, Optional pstrDelim As String = "- ") As String
Dim rs As New ADODB.Recordset
rs.Open pstrSQL, CurrentProject.Connection, adOpenKeyset, adLockReadOnly
Dim strConcat As String 'build return string
With rs
If Not .EOF Then
.MoveFirst
Do While Not .EOF
strConcat = strConcat & _
.Fields(0) & pstrDelim
.MoveNext
Loop
End If
.Close
End With
Set rs = Nothing
If Len(strConcat) > 0 Then
strConcat = Left(strConcat, _
Len(strConcat) - Len(pstrDelim))
End If
Concatenate = strConcat
End Function