Solved

SQL Qestion

Posted on 1998-07-16
4
197 Views
Last Modified: 2010-05-03
I would like to make an sql request (With an access databse) witch contain two compare operators. For example, i want the request to return only the records wtich contain the correct CustomerID AND the correct DateOrder. Following is the code i tried, but it doesn't work. Could anyone say me if it is possible to code it, and how do it ?

Dim MyDb as Database, ResultRequest as Recordset, CustID as Long
Set MyDb = OpenDatabase (MyDatabase)

Set ResultRequest = MyDb.OpenRecordset ( "Select * From [Order] " & "Where [OrderDate] = #" & Calendar1.value & "#" & "AND" & " [CustomerID] = #" & CustID & "#")

Where CustID come from another request of another table.
The system display me an error when trying to execute this code.

I hope someone know the correct answer.
Thank you in advance

BEST REGARDS
0
Comment
Question by:VB041898
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
shagnasty earned 50 total points
ID: 1465950
Should be:

If the CustID field is a string:

Set ResultRequest = MyDb.OpenRecordset ( "Select * From [Order] " & "Where [OrderDate] = #" & Calendar1.value & "#" & "AND" & " [CustomerID] = " & chr(34) & CustID & chr(34))

If it's numerical:

Set ResultRequest = MyDb.OpenRecordset ( "Select * From [Order] " & "Where [OrderDate] = #" & Calendar1.value & "#" & "AND" & " [CustomerID] = " & CustID)

Enclosing it in '#' pair means your specifying a date
0
 

Author Comment

by:VB041898
ID: 1465951
Thank you for your correct answer.
Could you say me where can i find all different syntax for SQL, witch all diffrents type of data.

BEST REGARDS
0
 
LVL 1

Expert Comment

by:shagnasty
ID: 1465952
VB5's online help has most of it (It's Jet specific, but should get you started).  Another good place to start is to use VisData (one of the sample apps that comes with VB5) to build your queries and statements.  Access too has a very good Query builder.  Other than that, your local library of bookshop should be able to point you in the right direction.
0
 

Author Comment

by:VB041898
ID: 1465953
Thank you for your answer

BEST REGARDS
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now