PDA

View Full Version : [SOLVED:] SQL Statement with WHERE condition



gmaxey
11-07-2013, 09:14 AM
I'm trying to load data from a Excel worksheet into a listbox. I only want the data where the value in column D (or four) is equal to one of three distinct values. I can't seem to get the SQL statement worked out.
The following works to load "all" the records:

m_oRecordSet.Open "SELECT * FROM [StaffData$], m_oConn, 3, 1"

I only want to load the records where the value in column D is "BPT" or "GPT" or "BP" this is one of several things I've tried, but all attempts returns a connection error:

m_oRecordSet.Open "SELECT * FROM [StaffData$] WHERE D='BPT' OR D='GPT' OR D='BP', m_oConn, 3, 1"

Thanks for any assistance:

Aflatoon
11-07-2013, 09:29 AM
Do you have a header row? If so

m_oRecordSet.Open "SELECT * FROM [StaffData$] WHERE [Fieldname]='BPT' OR [Fieldname]='GPT' OR [Fieldname]='BP'", m_oConn, 3, 1

If not, replace fieldname with F4

gmaxey
11-07-2013, 01:07 PM
Aflatoon, Thanks. It was the "F" part that I was missing.