|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have the same sql statement to generate a recordset, that I have to set a forms recordsource. The recordsource works fine, the recordset will not retrieve any rows using the LIKE operator. Here is the code: Any ideas? Thanks.
On Error GoTo Err_cmdSearch_Click Dim search_str As String Dim position1 As Integer Dim position2 As Integer Dim search_strA As String Dim position1A As Integer Dim position2A As Integer Dim new_recordset As String Dim cnn As New ADODB.Connection Dim rst As New ADODB.Recordset Dim sSQL As String search_str = Form_Customer!txt_name_search.Value position1 = InStr(search_str, "*") position2 = InStr(position1 + 1, search_str, "*") search_str = Replace(search_str, "*", "") If position2 <> 0 Then search_str2 = "*" & search_str & "*" Else search_str2 = search_str & "*" End If sSQL = "SELECT * FROM dbo_Customer WHERE (((CustName) Like '" & search_str2 & "'));" 'sSQL = "SELECT * FROM dbo_Customer WHERE (((dbo_Customer.CustName) = 'FULTON SUPPLY COMPANY'));" Set cnn = CurrentProject.Connection 'Set cnn = New ADODB.Connection 'cnn.Open "File Name=C:\SQLSERVERLINK.dsn" Set rst = New ADODB.Recordset 'rst.Open sSQL, cnn, adOpenDynamic, adLockPessimistic rst.Open "SELECT * FROM dbo_Customer WHERE (((CustName) Like '" & search_str2 & "'));", cnn, adOpenDynamic, adLockPessimistic MsgBox rst.Source rst.MoveFirst MsgBox rst!CustName Form_Customer.RecordSource = sSql Form_Customer.Requery Form_Customer.Refresh Exit_cmdSearch_Click: Exit Sub Err_cmdSearch_Click: MsgBox Err.Description Resume Exit_cmdSearch_Click End Sub |
|
#2
|
|||
|
|||
|
what happens if you try
Code:
.... LIKE '%value%'
__________________
- Rogier Doekes |
|
#3
|
|||
|
|||
|
"SELECT * FROM dbo_Customer WHERE (((dbo_Customer.CustName) = '%F%'));"
rst.Open sSQL, cnn, adOpenDynamic, adLockPessimistic MsgBox rst.Source rst.MoveFirst MsgBox rst!CustName Same thing: On the movefirst - Either BOF or EOF is true Is % the wildcard for SQL Server? Thanks, Elric |
|
#4
|
|||
|
|||
|
Upon further review, it did work.... once I changed the = back to LIKE :-)
Thanks, bud |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Like Operator Not Working With Linked SQL Server Table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|