ATTN: Phobos - Search -

B

Bill

I create "Find" Button on the form and use to look for the file number for
1-2-3
1-23
123

I use the form link to the table instead of Query. Is there a way for me to
use the button to look for anything 1-2-3 or 1-23 or 123 to pull up the file.

Recently, you give the code and it works for queries. I am trying to find a
way to use Table just like you give me the code. When I click the button
and pop up to look for the file number. I want to input either 1-2-3 or 1-23 or 123
to pull the file.

Your help would be great.

********************************************************

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
 
P

Phobos

Why not use the query with the function in it?

P


I create "Find" Button on the form and use to look for the file number for
1-2-3
1-23
123

I use the form link to the table instead of Query. Is there a way for me
to
use the button to look for anything 1-2-3 or 1-23 or 123 to pull up the
file.

Recently, you give the code and it works for queries. I am trying to find a
way to use Table just like you give me the code. When I click the button
and pop up to look for the file number. I want to input either 1-2-3 or
1-23 or 123
to pull the file.

Your help would be great.

********************************************************

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