Microsoft KB Archive/105173: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 58: Line 58:
The following example code selects every field from the Employees table in the Nwind.mdb sample database where the field Birth Date is greater than 12/31/1960. Nwind.mdb is the Microsoft Access sample database provided with Microsoft Access versions 1.0 and 1.1, and 2.0.
The following example code selects every field from the Employees table in the Nwind.mdb sample database where the field Birth Date is greater than 12/31/1960. Nwind.mdb is the Microsoft Access sample database provided with Microsoft Access versions 1.0 and 1.1, and 2.0.
<pre class="codesample">  ' Data1 is a data control.
<pre class="codesample">  ' Data1 is a data control.
   Data1.DataBaseName = &quot;C:\ACCESS\NWIND.MDB&quot;
   Data1.DataBaseName = "C:\ACCESS\NWIND.MDB"
   ' Enter the following two lines as one, single line:
   ' Enter the following two lines as one, single line:
   Data1.RecordSource = &quot;SELECT * FROM Employees
   Data1.RecordSource = "SELECT * FROM Employees


WHERE [Birth Date] &gt; #12/31/1960#&quot;
WHERE [Birth Date] &gt; #12/31/1960#"


   Data1.Refresh
   Data1.Refresh


   ' The following example uses FindFirst with the same Data Control:
   ' The following example uses FindFirst with the same Data Control:
   Data1.RecordSet.FindFirst &quot;[Hire Date] &lt;= #9/21/1992#&quot;
   Data1.RecordSet.FindFirst "[Hire Date] &lt;= #9/21/1992#"
                 </pre>
                 </pre>



Revision as of 09:43, 20 July 2020

Knowledge Base


How To Query for Dates Using a SQL Statement in Visual Basic

Article ID: 105173

Article Last Modified on 5/14/2007



APPLIES TO

  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 16-bit Enterprise Edition
  • Microsoft Visual Basic 3.0 Professional Edition
  • Microsoft Visual Basic 3.0 Professional Edition



This article was previously published under Q105173

SUMMARY

When you query for Dates in a Microsoft Access database, you may receive an incorrect result or a 'Type Mismatch' error message. To query for a date in a SQL statement in Visual Basic for Windows, enclose the date in pound signs (#).

NOTE: This article shows dates written in American format (MM/DD/YYYY). For example, 12/31/1960.

MORE INFORMATION

The following example code selects every field from the Employees table in the Nwind.mdb sample database where the field Birth Date is greater than 12/31/1960. Nwind.mdb is the Microsoft Access sample database provided with Microsoft Access versions 1.0 and 1.1, and 2.0.

   ' Data1 is a data control.
   Data1.DataBaseName = "C:\ACCESS\NWIND.MDB"
   ' Enter the following two lines as one, single line:
   Data1.RecordSource = "SELECT * FROM Employees

WHERE [Birth Date] > #12/31/1960#"

   Data1.Refresh

   ' The following example uses FindFirst with the same Data Control:
   Data1.RecordSet.FindFirst "[Hire Date] <= #9/21/1992#"
                

Keywords: kbhowto KB105173