ATTN: Phobos - Search

B

Bill

Hi Phobos,

Thanks, it works. I m really appreciated your help.

I have a question if that is possible to use your code into Find Button from the form to look RecordNumber either Table or Query. I copy the code "Find button" if you can help me to insert your code "Begin to End" into the code of "Find Button".

********** Find Button *******************
Private Sub cmdFind_Click()
On Error GoTo Err_cmdFind_Click

Me.Filter = ""
Me.FilterOn = False
'Screen.PreviousControl.SetFocus
Me.RecordNo.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_cmdFind_Click:
Exit Sub
Err_cmdFind_Click:
MsgBox Err.Description
Resume Exit_cmdFind_Click
End Sub
***************************************************************************************

'Code Begins
Function replace(fld As String, find As String, Optional repwith As String =
"") As String
Dim fldLen As Long
fldLen = Len(fld)

Dim findLen As Long
findLen = Len(find)

Dim newFld As String
newFld = ""

Dim x As Long
For x = 1 To fldLen
If Mid(fld, x, findLen) = find Then
newFld = newFld & repwith
x = x + findLen - 1
Else
newFld = newFld + Mid(fld, x, 1)
End If
Next

replace = newFld
End Function
'Code ends

In your query, one of the fields should be:

replace([fieldName],"-")

This removes hyphens (the default for the repWith argument is a
zero-length-string).

P
 
P

Phobos

Hi Bill,

I'm not sure what you are trying to do, could you be a bit more specific?

P



Hi Phobos,

Thanks, it works. I m really appreciated your help.

I have a question if that is possible to use your code into Find Button from
the form to look RecordNumber either Table or Query. I copy the code "Find
button" if you can help me to insert your code "Begin to End" into the code
of "Find Button".

********** Find Button *******************
Private Sub cmdFind_Click()
On Error GoTo Err_cmdFind_Click

Me.Filter = ""
Me.FilterOn = False
'Screen.PreviousControl.SetFocus
Me.RecordNo.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_cmdFind_Click:
Exit Sub
Err_cmdFind_Click:
MsgBox Err.Description
Resume Exit_cmdFind_Click
End Sub
****************************************************************************
***********

'Code Begins
Function replace(fld As String, find As String, Optional repwith As String =
"") As String
Dim fldLen As Long
fldLen = Len(fld)

Dim findLen As Long
findLen = Len(find)

Dim newFld As String
newFld = ""

Dim x As Long
For x = 1 To fldLen
If Mid(fld, x, findLen) = find Then
newFld = newFld & repwith
x = x + findLen - 1
Else
newFld = newFld + Mid(fld, x, 1)
End If
Next

replace = newFld
End Function
'Code ends

In your query, one of the fields should be:

replace([fieldName],"-")

This removes hyphens (the default for the repWith argument is a
zero-length-string).

P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top