|
-
Oct 4th, 2006, 08:20 PM
#1
[RESOLVED] Queries using the "LIKE" operator, Access works/VB isn't
Alright, I have a program querying a database to create a list of unique company names. It works fine, however, I'm adding a "filter" addition to it and so I'll be using the LIKE operator to make it work, obviously. The code works fine when using a normal query without LIKE, and otherwise returns empty, even if it -should- be able to find the records. When using the same query in Access, I returned 6 records, but in VB nothing seems to work. Can anyone see something I'm doing wrong, or something I could try to see if it would work..?
VB Code:
Dim qry As ADODB.Recordset, query As String
Set qry = New ADODB.Recordset
query = "SELECT DISTINCT companyname FROM companyrecords WHERE companyname LIKE '*a*'"
' this query works fine: "SELECT DISTINCT companyname FROM companyrecords"
qry.Open query, dbConn, adOpenDynamic, adLockReadOnly, adCmdText
If qry.EOF And qry.BOF Then
MsgBox "no records"
Exit Sub
End If
Do Until qry.EOF
MsgBox qry!CompanyName
qry.MoveNext
Loop
qry.Close
Set qry = Nothing
I'm clueless at this point, I've never worked with Access and VB before doing this project, and my experience with databases comes mostly from MySQL, but the syntax is nearly exactly the same, which is why I have no idea what's going wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|