Converting Characters

Dartagnan

Active Member
Joined
Jun 19, 2002
Messages
386
I have 2 tables I want to work with. Both tables have a loan number field. However, one tables loan number field has a text format and the other has a number format. When I try to run the query I receive "Type Mismatch in expression". Is there a way to convert the loan number, from either table, so the query can run?

Thank you
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Why don't you just change the Loan Number field in table 1 from text to number? You do this in the table design view.

Just make a duplicate of the table, just in case.
 
Upvote 0
Sorry, forgot to post the function!!!

Public Function StrToNumber(StringIn As String) As Variant
' Accepts a string and returns any numbers

On Error GoTo ErrorProcedure

Dim posn As Integer ' char position in string
Dim str As String ' holds numbers as we find them

For posn = 1 To Len(StringIn)
If IsNumeric(Mid(StringIn, posn, 1)) Then
str = str & Mid(StringIn, posn, 1)
End If
Next posn

If Len(str) > 0 Then
'Only for testing
Debug.Print str
StrToNumber = str
'Only for testing
Debug.Print StrToNumber
End If

ExitProcedure:
Exit Function
ErrorProcedure:
MsgBox "Error in function." & Err.number & Err.Description
Resume ErrorProcedure
End Function

David
 
Upvote 0

Forum statistics

Threads
1,221,494
Messages
6,160,141
Members
451,624
Latest member
TheWes

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