Using Wildcards in Access DB Find and Replace Scenarios

FFischer

Board Regular
Joined
Oct 10, 2013
Messages
59
I modified some code I borrowed from the MS Northwinds Training DB as follows.

Code:
Sub ReplaceMe()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim MyTable
MyTable = "Employees"
   Set MyDB = CurrentDb
   Set MyRS = MyDB.OpenRecordset(MyTable)
   MyRS.MoveFirst
   Do Until MyRS.EOF
    If MyRS![Job Title] = "Sales Representative" Then
         MyRS.Edit
         MyRS![Job Title] = "Marketing Representative"
         MyRS.Update
      End If
      MyRS.MoveNext
   Loop
End Sub

My goal is to perform find/replace functions much like in Excel. The above code works, however, I have not been able to incorporate wildcard statements, i.e, (In English) Find Sales* and Replace with Marketing*

Any help would be appreciated. Please don't bring up the discussion of Update queries.

Thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I modified some code I borrowed from the MS Northwinds Training DB as follows.

Code:
Sub ReplaceMe()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim MyTable
MyTable = "Employees"
   Set MyDB = CurrentDb
   Set MyRS = MyDB.OpenRecordset(MyTable)
   MyRS.MoveFirst
   Do Until MyRS.EOF
    If MyRS![Job Title] = "Sales Representative" Then
         MyRS.Edit
         MyRS![Job Title] = "Marketing Representative"
         MyRS.Update
      End If
      MyRS.MoveNext
   Loop
End Sub

My goal is to perform find/replace functions much like in Excel. The above code works, however, I have not been able to incorporate wildcard statements, i.e, (In English) Find Sales* and Replace with Marketing*

Any help would be appreciated. Please don't bring up the discussion of Update queries.

Thanks


Okay - For what it's worth, I solved the issue. Here is the code
Code:
Public Function ReplaceThings(MyTable As String, MyFind As String, MyReplace As String)
Dim MyDB As DAO.Database, MyRS As DAO.Recordset, MyRSField As Object
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(MyTable)
Set MyRSField = MyRS![Job Title]
    MyRS.MoveFirst
        Do Until MyRS.EOF
            MyRS.Edit
            MyRSField = Replace(MyRSField.Value, MyFind, MyReplace)
            MyRS.Update
            MyRS.MoveNext
        Loop
    MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
End Function

Sub ReplaceEmployeeJobTitleThings()
Call ReplaceThings("Employees", " - ", " ")
End Sub

Now I am faced with a new hurdle. I can define [Job Title] as a RecordSet Field in the function. However, I would like to make it behave like the string elements in the Sub. If I use [Job Title] I get the message "External Name Not Defined". Has anyone ever been able to assign a name to something in square brackets?
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top