Submitted By: Kent Finkle

Performs a Where In query to select Microsoft access records meeting one of three possible criteria.

Visual Basic
Edit|Remove
'  Script name:    SelectIn.vbs
'  Created on:      Tuesday, May 29, 2007
'  Author:             Kent Finkle
'  Purpose:          Demonstrate Access query based on list (Where..In). 
 
Const adOpenStatic = 3
Const adLockOptimistic = 3
 
Set objConnection = CreateObject("ADODB.Connection") 

Set objRecordSet = CreateObject("ADODB.Recordset")
 
objConnection.Open _
        "Provider= Microsoft.Jet.OLEDB.4.0; " & _
            "Data Source=C:\Scripts\Test.mdb"
 
sql = ""
sql = sql & "SELECT * "
sql = sql & "FROM Hardware "
sql = sql & "WHERE Location IN ('LA','NY','London') " 
sql = sql & "ORDER BY Location ASC; "
 
objRecordSet.Open sql , objConnection, adOpenStatic, adLockOptimistic
 
objRecordSet.MoveFirst
 
Do Until objRecordSet.Eof
    Wscript.Echo objRecordSet.Fields("Location").Value
    Wscript.Echo objRecordSet.Fields("Price").Value
    objRecordSet.MoveNext
Loop
 
objRecordSet.Close
objConnection.Close