Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of LIKE operator

Status
Not open for further replies.

muhaidib

Programmer
Sep 27, 2005
82
SA
Hi,
I am getting error
"The connection cannot be used to perform this operation. It is either closed or invalid in this context"

due to LIKE OPERATOR
while trying to open a recordset as follows:
rsUnReconCb.Open "SELECT * From CBRECON WHERE CBReconciled = False AND ( CBTag Like '" & "%" & rs121Tag!cbtag1 & "%'" & " Or CBTag Like " & "'*" & rs121Tag!cbtag2 & "*' ) , AdoCon, adOpenDynamic, adLockOptimistic"

SELECT statement reads as follows:
SELECT * From CBRECON WHERE CBReconciled = False AND ( CBTag Like '*bom*' Or CBTag Like '*del*' )

Please someone rectify the statement.

 
Hi,
I am getting error
"The connection cannot be used to perform this operation. It is either closed or invalid in this context"

due to LIKE OPERATOR
while trying to open a recordset as follows:
rsUnReconCb.Open "SELECT * From CBRECON WHERE CBReconciled = False AND ( CBTag Like '" & "*" & rs121Tag!cbtag1 & "*'" & " Or CBTag Like " & "'*" & rs121Tag!cbtag2 & "*' ) , AdoCon, adOpenDynamic, adLockOptimistic"

SELECT statement reads as follows:
SELECT * From CBRECON WHERE CBReconciled = False AND ( CBTag Like '*bom*' Or CBTag Like '*del*' )

Please someone rectify the statement.
 
This problem is sorted out as follws:

wrong statement:
rsUnReconCb.Open "SELECT * From CBRECON WHERE CBReconciled = False AND ( CBTag Like '" & "*" & rs121Tag!cbtag1 & "*'" & " Or CBTag Like " & "'*" & rs121Tag!cbtag2 & "*' ) , AdoCon, adOpenDynamic, adLockOptimistic"

correct statement:
rsUnReconCb.Open "SELECT * From CBRECON WHERE CBReconciled = False AND ( trim(CBTag) Like '%" & rs121Tag!cbtag1 & "%'" & " Or trim(CBTag) Like '%" & rs121Tag!cbtag2 & "%' )", AdoCon, adOpenDynamic, adLockOptimistic

silly error of putting inverted comma at end of statement. see line # 3 and 4

thanks
 
nice to see that when somebody solves their own problem

They Tell the solution !!!

Congratulations on manners

Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top