Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Trying to run an update query

I have an update query design with the source and the destination tables in the query designer.  But the joined fields are a text field in one table and a number field in the other table.   So naturally I'm getting a type mismatch error.  Is there some way to convert the text field to a number?  It will always truly be a number.

I tried ID: Val([textfieldname) but that didn't work.
Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

Try CInt(txtfield) if it is an integer you're joining to

If a long integer use CLng(txtfield)
or a double
CDbl(txtfield)

These will fail howver - if there are ANY non numeric values in the column.


Kelvin
Try using one of the conversion functions:

ID: CDbl(YourTextField)
"Tried" how exactly...?
Post the SQL you tried...

try: cdbl(YourTextField)
...if you need decimals

...or clng() if you only have whole numbers
You can ignore my post...
other experts were there first..
If you have control of the tables, the correct solution is to fix the data type discrepancy.  Otherwise, one the various type conversions already suggested will work.
Don't use Join but Where:

Select
   tblFirst.*,
   tblSecond.*
From
   tblFirst,
   tblSecond
Where
   tblFirst.IdNumeric = Val(tblSecond.IdText)

- or:

Where
   Trim(Str(tblFirst.IdNumeric)) = tblSecond.IdText

/gustav
Avatar of SteveL13

ASKER

I just tried :

Select
    tblFirst.*,
    tblSecond.*
 From
    tblFirst,
    tblSecond
 Where
    tblFirst.IdNumeric = Val(tblSecond.IdText)

But I get an error indicating that I can't use asterisks and that I need to add each field to the grid.

What should the code look like?  I have 13 fields in total.
Ok.  I have attached a file that I created by stripping everything else out of the real database.  I cannot get the update query to work because I'm sure I'm doing something wrong.  Can someone help?

Notes:

The ID field in tblNotes is numeric and has to be.
The ID field in tblTEMPORARY is text and has to be.

--Steve
Update-Qry-Example.accdb
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BINGO!!!  Thanks so much.
You are welcome!

/gustav