Fordraiders
asked on
Find and Replace Routine not working
.net 2003
access 2003
What Iam Doing...
Taking a value from a field...fldMfgname
See if it exists in another table txtFind...
If it does it is replaced with the txtReplace Value
Problem...
Ny Field value in fldMfgname keeps getting deleted to "" or null
i.e.
What it should do:
tblVendNameFindReplace =
txtFind txtReplace
BUSS BUSSMANN
tblData =
fldMfgname
BUSS
Replaced value is
BUSSMANN
iI keep getting the value in fldMfgname deleted...
Private Function AccessSandR()
Dim conn As System.Data.OleDb.OleDbCon nection
Dim tblVendNameFindReplace As New DataTable
Dim tblData As New DataTable
conn = New System.Data.OleDb.OleDbCon nection("P rovider=Mi crosoft.Je t.OLEDB.4. 0;Data Source=C:\Program Files\Dm2007\SkuCat.mdb")
'make dataadapters
Dim dac As New System.Data.OleDb.OleDbDat aAdapter(" SELECT fldId, txtFind, txtReplace FROM tblVendNameFindReplace ", conn)
Dim dad As New System.Data.OleDb.OleDbDat aAdapter(" SELECT fldID, fldDid, fldMfgname, fldMfrnum, fldDescription FROM tblData", conn)
Dim cb As New System.Data.OleDb.OleDbCom mandBuilde r(dad)
'get the datables from Access
dac.Fill(tblVendNameFindRe place)
dad.Fill(tblData)
'send updated table back to Access
For Each drc As DataRow In tblVendNameFindReplace.Row s
For Each drd As DataRow In tblData.Rows
If Not IsDBNull(drd("fldMfgname") ) Then drd("fldMfgname") = ReplaceWordsTemplate(drd(" fldMfgname "), drc("txtFind"), drc("txtReplace"))
Next
Next
dad.Update(tblData)
End Function
Private Function ReplaceWordsTemplate(ByVal SearchText As String, ByVal Token As String, ByVal ReplaceText As String) As String
Dim newtext As String = ""
newtext = SearchText.Replace(" " & Token & " ", " " & ReplaceText & " ")
'return result after removing space added at the end
Return newtext.Substring(0, newtext.Length - 1)
End Function
Thanks
fordraiders
access 2003
What Iam Doing...
Taking a value from a field...fldMfgname
See if it exists in another table txtFind...
If it does it is replaced with the txtReplace Value
Problem...
Ny Field value in fldMfgname keeps getting deleted to "" or null
i.e.
What it should do:
tblVendNameFindReplace =
txtFind txtReplace
BUSS BUSSMANN
tblData =
fldMfgname
BUSS
Replaced value is
BUSSMANN
iI keep getting the value in fldMfgname deleted...
Private Function AccessSandR()
Dim conn As System.Data.OleDb.OleDbCon
Dim tblVendNameFindReplace As New DataTable
Dim tblData As New DataTable
conn = New System.Data.OleDb.OleDbCon
'make dataadapters
Dim dac As New System.Data.OleDb.OleDbDat
Dim dad As New System.Data.OleDb.OleDbDat
Dim cb As New System.Data.OleDb.OleDbCom
'get the datables from Access
dac.Fill(tblVendNameFindRe
dad.Fill(tblData)
'send updated table back to Access
For Each drc As DataRow In tblVendNameFindReplace.Row
For Each drd As DataRow In tblData.Rows
If Not IsDBNull(drd("fldMfgname")
Next
Next
dad.Update(tblData)
End Function
Private Function ReplaceWordsTemplate(ByVal
Dim newtext As String = ""
newtext = SearchText.Replace(" " & Token & " ", " " & ReplaceText & " ")
'return result after removing space added at the end
Return newtext.Substring(0, newtext.Length - 1)
End Function
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect ...Thanks a million !
Open in new window