VB4.0 Sql query 
Author Message
 VB4.0 Sql query

I have a VB 4.0 application where i try to make a simple query
to a table where the key is of type Date. The database is
an MS Access 2.0 database.
The Sql statement which I tried first was:

Dim WantedDate as Date
SQL = "Select xxxx from Calendar where CalendarDate = "  &  WantedDate
Set MyRS = MyDB.OpenRecordset(SQL, dbOpenSnapshot)
..
..
Using this I get error code 3075.
I've tried many different methods to get the right SQL string, but no luck
so far.
Examples that I've found from Vb Faq's don't use a variable on the right
side of the query, so no help there.

Certainly should be a trivial case, but hope someone will tell the answer
anyway...I'm just stuck with this one.

Thanks in advance

Antti Maunula




Mon, 22 Mar 1999 03:00:00 GMT  
 VB4.0 Sql query

Dates in SQL queries have to be enclosed in #'s.....

i.e.:

SQL = "Select xxxx from Calendar where CalendarDate = #"  &  WantedDate & "#"



Mon, 22 Mar 1999 03:00:00 GMT  
 VB4.0 Sql query

Quote:

> I have a VB 4.0 application where i try to make a simple query
> to a table where the key is of type Date. The database is
> an MS Access 2.0 database.
> The Sql statement which I tried first was:
> Dim WantedDate as Date
> SQL = "Select xxxx from Calendar where CalendarDate = "  &  WantedDate

Access 2 seems to want to be told explicitly that what it's got is a date,
and this information is imparted unto it by surrounding the date with #
characters. Thus what you may find you'll need is:

  SQL = "Select xxxx from Calendar where CalendarDate = #"  &  WantedDate & "#"

Quote:
> Set MyRS = MyDB.OpenRecordset(SQL, dbOpenSnapshot)
> ..

--

Vox (0|+44)1642 216 200  }*|*{  *o|o*  }o|o{ Zetland Buildings, Exchange Square
Fax (0|+44)1642 216 201    o      o      *   Middlesbrough, Cleveland.  TS1 1DE
"Imitation is the sincerest form of being a thieving bastard." -- somebody else


Tue, 23 Mar 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. vb4 AND sql queries

2. how can I build 2 queries in 1 query(VB SQL query)

3. Running SQL Query with DBCS in VB4.0 and DAO 2.5

4. Open ended query system using SQL in VB4 32-bit

5. Help please - SQL query in VB4

6. SQL Queries in VB4.0/16

7. SQL queries in VB4

8. Q: VB4 RDO/Access95 How to use LIKE in SQL (or Access 95 queries)

9. SQL Query - MAX, Grouping and Sub query

10. SQL query works, Crystal query doesn't

11. Using Sub Query in Sql Query - Crystal Report 5.0

12. VB Query vs SQL Query Analyzer Speed?

 

 
Powered by phpBB® Forum Software