hi i want to know that how to use sound like query in VB.net with access.
EXAMPLE (SQL) -
create table names (name varchar(100))
insert into names values ('ritu')
select * from names where soundex(name) =soundex('reetu') OUTPUT-
ritu hi i want to know that how to use sound like query in VB.net with access.
EXAMPLE (SQL) -
create table names (name varchar(100))
insert into names values ('ritu')
select * from names where soundex(name) =soundex('reetu') OUTPUT-
ritu Quick summary and practical path forward. asked how to do a “sound‑like” query with Access from VB.NET. is correct that Access does not include a built‑in SOUNDEX, and ’s acbSoundex (from the Access Cookbook) is the usual VBA solution for use inside Access. However, saved Access queries that call VBA user‑defined functions generally will not be evaluated when you run SQL against the .mdb/.accdb via OLEDB/ODBC from another app — the engine used by external connections does not host Access’s VBA expression service. (support.microsoft.com)
Recommended options (choose by scale and deployment):
Small table / simple app: implement Soundex in your VB.NET code and filter results client‑side. That avoids Access/VBA portability issues and lets you compute codes once per input. The Soundex rules are standard (first letter + three-digit code) and many Access/VBA pages show implementations you can reimplement in .NET. (allenbrowne.com)
Medium/large data: add a small text column (e.g., SoundexCode) to the Access table, populate it on insert/update from your app, index it, and query WHERE SoundexCode = @code. Precomputing makes lookups fast and avoids fetching many rows. (If you need persistent computed columns at scale, server DBs offer better indexing.) (dba.stackexchange.com)
If you must run the VBA function as written: automate Access (CreateObject/Access.Application) and run the query inside Access (heavier, requires Access installed and trusted locations/sandbox settings). Sandbox/trust settings can also block expression evaluation when queries are run from non‑Access hosts. (stackoverflow.com)
Example VB.NET Soundex (drop into your data layer and use to populate a SoundexCode column):
Public Function SoundexCode(ByVal input As String) As String
If String.IsNullOrEmpty(input) Then Return String.Empty
Dim s = input.ToUpperInvariant()
Dim sb As New System.Text.StringBuilder()
sb.Append(s(0))
Dim prev As Char = "0"c
For i As Integer = 1 To s.Length - 1
Dim c = s(i)
Dim code As Char = "0"c
Select Case c
Case "B"c, "F"c, "P"c, "V"c : code = "1"c
Case "C"c, "G"c, "J"c, "K"c, "Q"c, "S"c, "X"c, "Z"c : code = "2"c
Case "D"c, "T"c : code = "3"c
Case "L"c : code = "4"c
Case "M"c, "N"c : code = "5"c
Case "R"c : code = "6"c
End Select
If code <> "0"c AndAlso code <> prev Then sb.Append(code)
If sb.Length = 4 Then Exit For
prev = If(code = "0"c, "0"c, code)
Next
While sb.Length < 4
sb.Append("0"c)
End While
Return sb.ToString()
End Function For larger or production deployments consider migrating lookup logic to a server DB that supports SOUNDEX/DIFFERENCE natively (or more advanced fuzzy libraries) so you can push matching into SQL rather than the client. (learn.microsoft.com)
Jump to Post— Teme64 215AFAIK MS Access does not have a built-in Soundex function. You have to write your own. Here's an article from MSDN: Building Microsoft Access Applications with VB (VBA?) code for Soundex function. See …
AFAIK MS Access does not have a built-in Soundex function. You have to write your own. Here's an article from MSDN: Building Microsoft Access Applications with VB (VBA?) code for Soundex function. See if it's for any help.
hi i want to know that how to use sound like query in VB.net with access.
EXAMPLE (SQL) -
create table names (name varchar(100)) insert into names values ('ritu') select * from names where soundex(name) =soundex('reetu')OUTPUT-
ritu
Hi I got this from The O'Reilly Access Cook Book. Has worked wonders for me.
Paste it into a module then use acbsoundex() in stead of soundex in your SQL statement.
Enjoy
Public Function acbSoundex( _
ByVal varSurName As Variant) As Variant
' Purpose:
' Takes a surname string and returns a 4-digit
' code representing the Russell Soundex code.
' In:
' varSurName: A surname (last name) as a variant
' Out:
' Return value: A 4-digit Soundex code as a variant
On Error GoTo HandleErr
Dim intLength As Integer
Dim intCharCount As Integer
Dim intSdxCount As Integer
Dim intSeparator As Integer
Dim intSdxCode As Integer
Dim intPrvCode As Integer
Dim varChar As Variant
Dim varSdx As Variant
Const acbcSoundexLength = 4
' We add "" to take care of a passed Null
intLength = Len(varSurName & "")
If intLength > 0 Then
intSeparator = 0 'Keeps track of vowel separators
intPrvCode = 0 'The code of the previous char
intCharCount = 0 'Counts number of input chars
intSdxCount = 0 'Counts number of output chars
'Loop until the soundex code is of acbcSoundexLength
'or we have run out of characters in the surname
Do Until (intSdxCount = acbcSoundexLength Or intCharCount = intLength)
intCharCount = intCharCount + 1
varChar = Mid(varSurName, intCharCount, 1)
'Calculate the code for the current character
Select Case varChar
Case "B", "F", "P", "V"
intSdxCode = 1
Case "C", "G", "J", "K", "Q", "S", "X", "Z"
intSdxCode = 2
Case "D", "T"
intSdxCode = 3
Case "L"
intSdxCode = 4
Case "M", "N"
intSdxCode = 5
Case "R"
intSdxCode = 6
Case "A", "E", "I", "O", "U", "Y"
intSdxCode = -1
Case Else
intSdxCode = -2
End Select
'Special case the first character
If intCharCount = 1 Then
varSdx = UCase(varChar)
intSdxCount = intSdxCount + 1
intPrvCode = intSdxCode
intSeparator = 0
'If a significant constant and not a repeat
'without a separator then code this character
ElseIf intSdxCode > 0 And _
(intSdxCode <> intPrvCode Or intSeparator = 1) Then
varSdx = varSdx & intSdxCode
intSdxCount = intSdxCount + 1
intPrvCode = intSdxCode
intSeparator = 0
'If a vowel, this character is not coded,
'but it will act as a separator
ElseIf intSdxCode = -1 Then
intSeparator = 1
End If
Loop
'If the code is < acbcSoundexLength chars long, then
'fill the rest of code with zeros
If intSdxCount < acbcSoundexLength Then
varSdx = varSdx & String((acbcSoundexLength - intSdxCount), "0")
End If
acbSoundex = varSdx
Else
acbSoundex = Null
End If
ExitHere:
On Error GoTo 0
Exit Function
HandleErr:
Select Case Err
Case Else
MsgBox Err & ": " & Err.Description, _
vbOKOnly + vbCritical, "acbSoundex"
End Select
Resume ExitHere
End Function We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.