esteiner
Programmer
- Oct 31, 2003
- 24
I have been trying to solve performance problems with some of my VBA code. Several members have suggested using the following user defined public function within an Access query. I did create a separate module for this function:
Public Function NumPart(fld As String) As String
Dim n As Integer
For n = 1 To Len(fld)
If IsNumeric(Mid(fld, n, 1)) Then
NumPart = Right(fld, Len(fld) - n + 1)
Exit For
End If
Next
End Function
Here is the form code and query.....
Private Sub cmdSplitMPN_Click()
On Error GoTo E_Handle
Dim strTableName As String
Dim strSQL As String
Set db = DAO.DBEngine(0)(0)
strTableName = "pull_inv_BRE"
strSQL = "UPDATE [" & strTableName & "] " & _
"SET [CorePartNumber] = NumPart(manfPartNum) " & _
"Where manfPartNum LIKE '*[0-9]*' "
db.Execute strSQL
sExit:
On Error Resume Next
Reset
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
I receive the Error: 3085 Undefined funtion "NumPart" in expression. My research suggests that Access will not allow a user defined function to be used within the query. Is this true? If this is truly a limitation of Access, can anyone suggest an alternative?
Thank you in advance for you help. I am banging my head against the wall here.
Public Function NumPart(fld As String) As String
Dim n As Integer
For n = 1 To Len(fld)
If IsNumeric(Mid(fld, n, 1)) Then
NumPart = Right(fld, Len(fld) - n + 1)
Exit For
End If
Next
End Function
Here is the form code and query.....
Private Sub cmdSplitMPN_Click()
On Error GoTo E_Handle
Dim strTableName As String
Dim strSQL As String
Set db = DAO.DBEngine(0)(0)
strTableName = "pull_inv_BRE"
strSQL = "UPDATE [" & strTableName & "] " & _
"SET [CorePartNumber] = NumPart(manfPartNum) " & _
"Where manfPartNum LIKE '*[0-9]*' "
db.Execute strSQL
sExit:
On Error Resume Next
Reset
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
I receive the Error: 3085 Undefined funtion "NumPart" in expression. My research suggests that Access will not allow a user defined function to be used within the query. Is this true? If this is truly a limitation of Access, can anyone suggest an alternative?
Thank you in advance for you help. I am banging my head against the wall here.