A
Alberto Uttranadhie
Hi, everybody,
I have an ADO recordset from which I would like to get its
rows values to be used in a subform's filter. Here are my
codes:
Public Function MyFunction()
On Error Goto Err_MyFunction
Dim cnt As Long
Dim frm As Form
Dim lng As Long
Dim rst As New ADODB.Recordset
Dim str As String
Dim strRef As String
lng = Me.IdDocument
str = "SELECT Reference FROM tblReferences " _
& "WHERE tblReferences.IdDocument = " & lng & ";"
rst.Open str, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
cnt = 1
Do Until rst.EOF
If cnt = 1 Then
strRef = "LIKE '" & rst.GetRows(-1, cnt) & "'"
cnt = cnt + 1
Else
strRef = strRef & " OR LIKE '" & rst.GetRows(-
1, cnt) & "'"
cnt = cnt + 1
If rst.EOF Then
Exit Do
End If
End If
Loop
rst.Close
Set frm = Form_frmMyForm
With frm
.Filter = "[Reference] " & strRef
.FilterOn = True
End With
Exit_MyFunction:
Exit Function
Err_MyFunction:
MsgBox Err.Description
Resume Exit_MyFunction
End Function
As you can read what I am trying is to get a string in
which I am be able to insert an string as "OR LIKE" in
case of more that one record returned to be used as s
filter.
I also tried GetString method but, although it is possible
to write the same insertion it also appears at the end of
the string (e.g., "84-789-13-0 OR LIKE 84-789-45-0 OR
LIKE").
So, what am I doing wrong with GetRows method or is there
any other that works better?
As always, thanks in advance.
Alberto Uttranadhie (Spain)
I have an ADO recordset from which I would like to get its
rows values to be used in a subform's filter. Here are my
codes:
Public Function MyFunction()
On Error Goto Err_MyFunction
Dim cnt As Long
Dim frm As Form
Dim lng As Long
Dim rst As New ADODB.Recordset
Dim str As String
Dim strRef As String
lng = Me.IdDocument
str = "SELECT Reference FROM tblReferences " _
& "WHERE tblReferences.IdDocument = " & lng & ";"
rst.Open str, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
cnt = 1
Do Until rst.EOF
If cnt = 1 Then
strRef = "LIKE '" & rst.GetRows(-1, cnt) & "'"
cnt = cnt + 1
Else
strRef = strRef & " OR LIKE '" & rst.GetRows(-
1, cnt) & "'"
cnt = cnt + 1
If rst.EOF Then
Exit Do
End If
End If
Loop
rst.Close
Set frm = Form_frmMyForm
With frm
.Filter = "[Reference] " & strRef
.FilterOn = True
End With
Exit_MyFunction:
Exit Function
Err_MyFunction:
MsgBox Err.Description
Resume Exit_MyFunction
End Function
As you can read what I am trying is to get a string in
which I am be able to insert an string as "OR LIKE" in
case of more that one record returned to be used as s
filter.
I also tried GetString method but, although it is possible
to write the same insertion it also appears at the end of
the string (e.g., "84-789-13-0 OR LIKE 84-789-45-0 OR
LIKE").
So, what am I doing wrong with GetRows method or is there
any other that works better?
As always, thanks in advance.
Alberto Uttranadhie (Spain)