Inizia con la creazione di una nuova procedura sub utilizzando il seguente codice : Private Sub 
 
useVariablesInQuery ( ) economici 2
 Digitare il seguente codice per creare le variabili che si intende utilizzare nella query : 
 
 Dim strSQL As String Dim 
 
 companyName Come 
 String 
 Dim lastName As String 
 
 Dim rst come Recordset 
 
 Dim dbs As Database 
 
 Set dbs = CurrentDb 
 3 
 digitare quanto segue per definire i valori delle variabili utilizzate nella query : 
 
 companyname = " Northwind Traders " 
 
 lastName = " Freehafer " 
 4 
 Tipo l' seguito per creare una query utilizzando le variabili nel passaggio precedente : 
 
 strSQL = " . . SELEZIONA Employees.Company , Lavoratori [ Cognome ] , Lavoratori [ Nome ] , " 
 
 strSQL = strSQL & " Dipendenti . [E - mail] " 
 
 strSQL = strSQL & " FROM Impiegati " 
 
 strSQL = strSQL & "WHERE ( ( ( Employees.Company ) = ' " & ( companyName ) & " ') " 
 
 strSQL = strSQL & "AND ( ( Employees. [ Cognome ] ) =' " & ( lastName ) & " ')); " 
 5 
 Digitare quanto segue per aprire un recordset e di visualizzare i risultati della query : 
 
 Set rst = dbs.OpenRecordset ( strSQL ) 
 
Debug.Print rst.Fields ( 0 ) Valore < . br>
 Debug.Print rst.Fields (1). Valore 
 
 Debug.Print rst.Fields (2). Qualità 
 
 Debug.Print rst.Fields (3). Valore 
 6 
 digitare quanto segue per terminare la procedura di sub : 
 
 rst.Close 
 
 dbs.Close 
 
End sub 
Programmazione © www.354353.com