1

A Microsoft Access implementation is throwing a type mismatch error while trying to execute a macro that opens up some queries. Most of the tables are linked to a SQL Server and I need to join two of the tables together that have different datatypes.

Table A:
REFERENCE TEXT

Table B:
REFNO NUMBER

I would ordinarily want to correct the issue on the SQL Server side, but there are multiple apps hitting the same database and it would take a considerable amount of time to test all of them. Furthermore, we are in the process of completely rewriting this application and any work I do today is completely throw-away...

If there is a way to make this join possible in access, I would save all kinds of time...

3 Answers 3

3

Within Access you could use the CLng (or Cint) function to convert the Table A's REFERENCE values from text to number.

I would prefer to create a view of Table A in SQL Server to transform the field's data type before Access gets the data. You shouldn't need to test the view against your other existing apps. When your re-write make the view no longer useful, just discard it.

1
  • I was able to accomplish this by creating a view on the SQL DB and then brought that into Access and replaced the table with the view for the queries. Thanks for the quick suggestion.
    – RSolberg
    Aug 4, 2009 at 18:53
2

You can do the comparison in the criteria.

SELECT [REFERENCE], [REFNO]
FROM [Table a], [Table b]
WHERE [REFERENCE]=cstr(nz([REFNO],""))

You can also do a passthrough - a query in access that executes on the sql server and returns only the data.

SELECT [REFERENCE], [REFNO]
FROM [Table a], [Table b]
WHERE [REFERENCE]=cast([REFNO] as varchar(25))

HTH

1

What is the datatype for each of the column, you mentioned?

If you want to compare it stringwise, you could do Cstr(myNumericColumn) = myStringColumn.
OR to compare it in numeric mode, do CLng(myStringColumn) = myNumericColumn.

3
  • its above, tableA has a text column while tableB has a integer column.
    – RSolberg
    Aug 4, 2009 at 16:54
  • You can use either of the above, depending on how you wish to compare. Aug 4, 2009 at 17:16
  • I dont know what you mean by that. Could you explain as to why using Cstr or Clng doesn't help in your case? Aug 4, 2009 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.