|
-
Feb 28th, 2006, 09:43 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How can I find something in a field
I have an access database with many fields (Client, City, House Model and many others...)
In the "Client" field, there's the Name and the First Name (for example Jack Strap)
I want to find in my database all records with the name Strap in the "Client" field ?
Help me ! Thanks !
-
Feb 28th, 2006, 09:47 AM
#2
Re: How can I find something in a field
Use Like operator.
VB Code:
Select * from YourTable Where Client Like "*Strap*"
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Feb 28th, 2006, 09:57 AM
#3
Thread Starter
Hyperactive Member
Re: How can I find something in a field
I'm not really sure if I understand...I have only to do this:
VB Code:
Data1.Recordset.MoveFirst
Do
If Data1.Recordset.Fields("Client").Value = "*Strap*" Then
msgbox "Item found"
End If
Data1.Recordset.MoveNext
If Data1.Recordset.EOF = True Then
Exit Do
End If
Loop
-
Feb 28th, 2006, 09:58 AM
#4
Hyperactive Member
Re: How can I find something in a field
VB Code:
MyRst.open "select * from myTable where firstname like %'Strep' %'"
This will return all records from firstname field where strep is exist .
-
Feb 28th, 2006, 10:02 AM
#5
Re: How can I find something in a field
 Originally Posted by DubweiserTM
I'm not really sure if I understand...I have only to do this:
VB Code:
Data1.Recordset.MoveFirst
Do
If Data1.Recordset.Fields("Client").Value = "*Strap*" Then
msgbox "Item found"
End If
Data1.Recordset.MoveNext
If Data1.Recordset.EOF = True Then
Exit Do
End If
Loop
Seems like you are using Data Controls.
You should ne using the ADODB connection and recordsets in VB and not Data Controls. Data Controls are no good. Search this form and you will get lot of samples on how to use ADO.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Feb 28th, 2006, 10:14 AM
#6
Thread Starter
Hyperactive Member
Re: How can I find something in a field
I dont know how to use this, but I found a tutorial on this...
Is it really better than DAO ?
Thanks for your suggestion !
-
Feb 28th, 2006, 10:17 AM
#7
Re: How can I find something in a field
 Originally Posted by DubweiserTM
Is it really better than DAO ?
Yes.
In addition, you will find the doing everything through code rather than using bound controls will give you a lot more flexibility and control over what your program does, how it does it and when it does it.
-
Feb 28th, 2006, 10:39 AM
#8
Re: How can I find something in a field
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 28th, 2006, 02:34 PM
#9
Thread Starter
Hyperactive Member
Re: [RESOLVED] How can I find something in a field
Originally Posted by zubairkhan
MyRst.open "select * from myTable where firstname like %'Strep' %'"
I tried to understand something in this line ? Who can help me ?
Sorry but I'm Beginner with ADO...
Thanks !
Last edited by DubweiserTM; Feb 28th, 2006 at 02:58 PM.
-
Feb 28th, 2006, 03:36 PM
#10
Thread Starter
Hyperactive Member
Re: [RESOLVED] How can I find something in a field
I followed the ADO Tutorial but is there nothing about "Select" ?
Is it complicated to use ADO or I'm stupid ?
Help me please ! Thanks !
-
Feb 28th, 2006, 03:59 PM
#11
Re: [RESOLVED] How can I find something in a field
Here is a short example of connection and retrieving data from a table in an Access db.
VB Code:
Option Explicit
'Add a reference to MS ActiveX 2.x Data Objects library
Private Sub Command1_Click()
On Error GoTo MyError
Dim oCnn As ADODB.Connection
Dim oRs As ADODB.Recordset
Dim sSQL As String
Set oCnn = New ADODB.Connection
oCnn.Connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"
oCnn.Open
Set oRs = New ADODB.Recordset
sSQL = "SELECT * FROM Table1;"
oRs.Open sSQL, oCnn, adOpenKeyset, adLockOptimistic, adCmdText
If oRs.BOF = False And oRs.EOF = False Then
Do While oRs.EOF = False
MsgBox oRs.Fields("Field1").Value
oRs.MoveNext
Loop
Else
MsgBox "No Records Returned"
End If
oRs.Close
Set oRs = Nothing
oCnn.Close
Set oCnn = Nothing
Exit Sub
MyError:
MsgBox Err.Number & " - " & Err.Description
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 28th, 2006, 04:26 PM
#12
Thread Starter
Hyperactive Member
Re: [RESOLVED] How can I find something in a field
For example, Field1 contains Date (ex: 30-12-2005)
How to find in Field1, all Date with 2005 ???
Thanks !
-
Feb 28th, 2006, 04:50 PM
#13
Re: [RESOLVED] How can I find something in a field
Instead of ...
sSQL = "SELECT * FROM Table1;"
You would pass a sql string that will filter the table to the record(s) your looking for.
sSQL = "SELECT * FROM Table1 WHERE Field1 = #30-12-2005#;"
Field1 must be defined in the table as a Date Field Data type or you need a different syntax.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 1st, 2006, 09:24 AM
#14
Thread Starter
Hyperactive Member
Re: [RESOLVED] How can I find something in a field
Am I stupid or SQL is very complicated ???
Thanks for your help RobDog888 but this line returns only this date 30-12-2005
VB Code:
sSQL = "SELECT * FROM Table1 WHERE Field1 = #30-12-2005#;"
I use this statement and all records with 2005 are found:
VB Code:
sSQL = "SELECT * FROM Table1 WHERE Field1 like '%2005%'"
Another questions regarding these two lines:
(a) sSQL = "SELECT * FROM Table1 WHERE Dépositaire like '%home%' ;"
(b) sSQL = "SELECT * FROM Table1 WHERE Dépositaire like '*eric*' ;"
Why (a) returns many records and (b) returns nothing ?
Last edited by DubweiserTM; Mar 1st, 2006 at 11:32 AM.
-
Mar 1st, 2006, 01:18 PM
#15
Re: [RESOLVED] How can I find something in a field
Because when using ADO the wild card cahracter is the "%" and not then "*".
Sorry, I thought you wanted a particular date, but if you want a date range, like all 2005, then you can modify the stateement like so.
VB Code:
sSQL = "SELECT * FROM Table1 WHERE YEAR([Field1]) = 2005;"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 18th, 2006, 11:26 AM
#16
Junior Member
Re: [RESOLVED] How can I find something in a field
i was trying to get a user input, using a text box, i put the txt from the user input into varbale called nameSearch and added the code below Now i get error "-2147217904- No value given for one or more required prams"
So i did a step through on the program and checked the var nameSearch, and it did indeed contain the data.
Im just wondering if its my syntax that is incorrect, or just my code
sSQL = "SELECT * FROM patient WHERE Name = " & nameSearch & " "
'sSQL = "SELECT * FROM patient;"
rs.Open sSQL, cn, adOpenKeyset, adLockOptimistic, adCmdText
If rs.BOF = False And rs.EOF = False Then
Do While rs.EOF = False
List1.AddItem rs.Fields("ID")
rs.MoveNext
Loop
Else
MsgBox "No Records Returned"
End If
when i used the code from the example it outputs all the ID's into the list box
-
Mar 18th, 2006, 12:28 PM
#17
Re: [RESOLVED] How can I find something in a field
Your syntax isn't quite correct, text data needs to be enclosed in single quotes, and Name is a reserved word (which can cause problems) so needs to be in square brackets - like this:
VB Code:
sSQL = "SELECT * FROM patient WHERE [Name] = [B]'[/B]" & nameSearch & "[B]'[/B] "
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
|