P
Paul
I executed the followinh functions to eliminate some characters in a record
on a table. It seems to me that the function is only updating the first
record on the table even though it loops through all the records in the
recordset. Thanks
Option Compare Database
Option Explicit
Dim strFindAndReplace As String
Function ConvertString()
Dim db1 As DAO.Database
Dim rst1 As DAO.Recordset
Dim db2 As DAO.Database
Dim rst2 As DAO.Recordset
Dim rst3 As DAO.Recordset
Dim strComment As String
Set db1 = CurrentDb
Set rst1 = db1.OpenRecordset("Tbl_Inventory_Detail", dbOpenDynaset)
If Not rst1.BOF Then
rst1.MoveFirst
Do While Not rst1.EOF
strComment = rst1!Comment
Debug.Print strComment & " - " & rst1!InventoryDetailID
Call FindAndReplace(strComment, vbCrLf & vbCrLf, "; ")
Set db2 = CurrentDb
Set rst2 = db2.OpenRecordset("Tbl_Inventory_Detail",
dbOpenDynaset)
rst2.Filter = rst1!InventoryDetailID
Set rst3 = rst2.OpenRecordset
On Error Resume Next
Debug.Print rst3!Comment
rst3.Edit
rst3!Comment = strFindAndReplace
rst3.Update
Debug.Print rst3!Comment
Set rst2 = Nothing
Set rst3 = Nothing
Set db2 = Nothing
rst1.MoveNext
Loop
End If
Set rst1 = Nothing
Set db1 = Nothing
End Function
Function FindAndReplace(ByVal strInString As String, _
strFindString As String, _
strReplaceString As String) As String
Dim intPtr As Integer
If Len(strFindString) > 0 Then 'catch if try to find empty string
Do
intPtr = InStr(strInString, strFindString)
If intPtr > 0 Then
FindAndReplace = FindAndReplace & Left(strInString, intPtr -
1) & _
strReplaceString
strInString = Mid(strInString, intPtr +
Len(strFindString))
End If
Loop While intPtr > 0
End If
FindAndReplace = FindAndReplace & strInString
strFindAndReplace = FindAndReplace
Debug.Print strFindAndReplace
End Function
on a table. It seems to me that the function is only updating the first
record on the table even though it loops through all the records in the
recordset. Thanks
Option Compare Database
Option Explicit
Dim strFindAndReplace As String
Function ConvertString()
Dim db1 As DAO.Database
Dim rst1 As DAO.Recordset
Dim db2 As DAO.Database
Dim rst2 As DAO.Recordset
Dim rst3 As DAO.Recordset
Dim strComment As String
Set db1 = CurrentDb
Set rst1 = db1.OpenRecordset("Tbl_Inventory_Detail", dbOpenDynaset)
If Not rst1.BOF Then
rst1.MoveFirst
Do While Not rst1.EOF
strComment = rst1!Comment
Debug.Print strComment & " - " & rst1!InventoryDetailID
Call FindAndReplace(strComment, vbCrLf & vbCrLf, "; ")
Set db2 = CurrentDb
Set rst2 = db2.OpenRecordset("Tbl_Inventory_Detail",
dbOpenDynaset)
rst2.Filter = rst1!InventoryDetailID
Set rst3 = rst2.OpenRecordset
On Error Resume Next
Debug.Print rst3!Comment
rst3.Edit
rst3!Comment = strFindAndReplace
rst3.Update
Debug.Print rst3!Comment
Set rst2 = Nothing
Set rst3 = Nothing
Set db2 = Nothing
rst1.MoveNext
Loop
End If
Set rst1 = Nothing
Set db1 = Nothing
End Function
Function FindAndReplace(ByVal strInString As String, _
strFindString As String, _
strReplaceString As String) As String
Dim intPtr As Integer
If Len(strFindString) > 0 Then 'catch if try to find empty string
Do
intPtr = InStr(strInString, strFindString)
If intPtr > 0 Then
FindAndReplace = FindAndReplace & Left(strInString, intPtr -
1) & _
strReplaceString
strInString = Mid(strInString, intPtr +
Len(strFindString))
End If
Loop While intPtr > 0
End If
FindAndReplace = FindAndReplace & strInString
strFindAndReplace = FindAndReplace
Debug.Print strFindAndReplace
End Function