Field Type Mismatch on select

A

AJ

I have an input field (InputFieldA) that a user can type either a location#
(alphanumeric - could be all numeric) or zipcode (numeric).
I have the following select:

select * from TableA
where location = InputFieldA

I would like to just do something simple to select the information
regardlesss of whether they type in location# or zip. I thought something
like this would work:

select * from TableA
where location = InputFieldA
or zipcode = InputFieldA

This works if the field is a zipcode (numeric) but not if it contains
characters because it fails with a mis match on field type. (The location is
in quotes, the zipcode is not)

All the code is based on the loaction# so ideally that is what I am trying
to get to. Any thoughts?? Thanks.
 
W

Wayne-I-M

Hi

You could change the format of the zipcode to text.

BUT MAKE A BACKUP FIRST - I'm not sure about US zipcode but I think they are
not used in calculations so they can be placed as text.
 
T

Tom Wickerath

Why does your zipcode field need to remain numeric? You're likely not going
to be performing mathematical operations on zip code data. The following
query works just fine in the sample Northwind database, when search criteria
is entered into a textbox named InputFieldA, in a form named "Form1":

SELECT * FROM Employees
WHERE (((Employees.City)=[Forms]![Form1]![InputFieldA]))
OR (((Employees.PostalCode)=[Forms]![Form1]![InputFieldA]));


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

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

Similar Threads

Entering Data In Form Field 2
XBase programmer needs help understanding Access 33
Auto populate fields 5
Dlookup 6
Type Mismatch 4
"data type mismatch" 6
Code problems 1
code help needed 1

Top