    48  

     3.         

        ()   ,   Database, Tablf 
Recordset  QueryDef,   ,   
         
,     . 

    3.1.   

           .  
    ,   
!         . 

    | DBEngine	""]    
    -\ Errors (Error)	|  
    | Workspaces (Workspace)  j   
    -\ Groups (Group)	|   
    -| Users (User)	~|   Databases (Database)     ~|   
    -j Recordsets (Recordset)   "|   
    -| QueryDefs (QueryDef)     ~]  
    -\ TableDefs (TableDef)	|  
    -| Relations (Relation)         ~|  
    -| Containers (Container)     ~]  

    . 3.1.   . 

            Jet ( 
DBEngine).         
   . 
    ,     : 

    Set   dbDbl   =  DBEngine.Workspaces(0).OpenDatabase("Dbl.mdb") 

               
  . 

    	 

    Workspace	   ._____________________ 
    Database	  ._________________________ 


     3.      ______________49 

    	 

Recordset       
    ,     . 

QueryDef        
  .

TableDef
  .

    :          . 
  ,   Visual Basic     
      .    
        .mdb  
  ,  Microsoft Access. 

    3.1.1.  DBEngine  Workspace 

              , 
     DBEngine    (. 
 " Workspace"). 

     DBEngine 

     DBEngine        .  
       . 
        ,    Version 
 DBEngine.        
 RepairDatabase  CompactDatabase  DBEngine.   
     Version   RepairDatabase. 

    MsgBox   "        -   "   &  _ 
    DBEngine.Version     '             
	DBEngine.RepairDatabase   ":\DB1.MDB" 


     Workspace 

     Workspace    ( )  
,      .   
     Workspace,   Hcnonb3yeTcg_.DBEngine.Workspaces(0). 

    :    ,  
   Microsoft Jet.  ,   
,  ,     .  
,    ,     
,   ,     
  .       Workspace. 

         CreateWorkspace  DBEngine 
     ,     
 Microsoft Jet     : 

    Dim wspNew as Workspace 
    Set wspNew = DBEngine.CreateWorkspace _ 
    ("NewJetWorkspace", "Admin", "", dbUseJet) 

           Workspace. 
         
 . 

    :       , 
       , , 
  .         
,          
.         
   ,   DBEngine 


    50  L 

 Workspace   . Visual Basic   
  DBEngine.Wbfkspaces (0). 

    3.1.2.      

              .   
     Database,      
   OpenDatabase. 

       

      Database    . 
       Set. 
             : 

    Dim  dbDbl   As   Database Set   dbDbl   =  OpenDatabase  _ ("C:\VB\Nwind.mdb") 

     OpenDatabase 

      OpenDatabase: 

    Set _ - _.OpenDatabase (__, , 
__, _) 

      OpenDatabase    : 

    	 

     	 ,   Database,   
 . 
    _	.  ,   
  Workspace,     Database.  
  _  ?    . 
    _ _ 	,     . 
    	     Microsoft Jet  True  False  
     = True,  !    
   .      , 
    .     False. 
    __	True  False.  True,   . 
    False. 

    _ 

    ,    ,  . 

    :    ,      
  , : \\server1\dir1\Db1.mdb. 

     Close 

            ,   
Close,  t  : 

    dbDbl.Close 


     3.      	51 


    3.2.     

           .    
       Recordset. 
         ,    
, ,   .      
 -MeHHafl^i^^beTcrRecordset1,     OpenRecordset. 

    3.2.1.   Recordset 

      Recordset    .  
       Set. 
              : 

    Dim dbDbl   As   Database 
    Dim recEmployees  As   Recordset 
    Set dbDbl = OpenDatabase("C:\VB\Nwind.mdb") 
    Set recEmployees = dbDbl.OpenRecordset("Employees") 

      OpenRecordset: 

    Set o6beKm_Recordset = .OpenRecordset (, , , ) 

          OpenRecordset: 

    	__ __ 

    o6b6Km_Recordset    ,   Recordset, 
 _________ .____ _ ____ __________ ____ _ 
    	  ,       ( 
, , ,   ),   -_________ 
  Recordset.____________________                   
    .   , 
-___________  ,     SQL.______     
                                        
dbOpenTable, __________ dbOpenDynaset  dbOpenSnapshot.___________ ______ 
                        ,     . 
,           
( ___________dbForwardOnly).__ __________ ______ __ _      ____ 
    	    . ,   
       dbPessimistic,  
    I	     .  
     .   "    Microsoft 
    Jet"  4 "    
    _________        ".__________________________________ 
    ,        : 
    Dim  recorders  As   Recordset 
    Set   recorders   =   dbDbl.OpenRecordset  _ 
    ("Orders",   dbOpenDynaset,   dbForwardOnly) 
              
   Recordset: 


    52	    

    Select Case recWhatType.Type Case dbOpenTable 
    Msgbox " -    table" Case dbOpenDynaset 
    Msgbox " -    dynaset" Case dbOpenSnapshot 
    Msgbox " -    snapshot" End Select 


    3.2.2.   Recordset 

         Microsoft Jet     
: tal dynaset, snapshot  forward-only. 
    Table.    table      
      .     
   .      table  
  .        
,  ;   MicrosofJ"Jetr|JaHHbie  
    ; .    
 .   4'"     ". 
    Dynaset.    dynaset    ,  
MOI         . Dynaset  
;  .   "  dynaset   
   .       
  . Dynaset  __    
 *    ,    
.        ,  dynaset 
 ,       .  
         . 
    Snapshot.    snapshot       
   .   ,  ,  
        snapshot. Snapshot    
    ,     . 
Snapshot    ,       
 . 
   Forward-Only.    forward-only     
snapshot,;  ,      . 

       Recordset 

          ,    
   . 
          ,  
   table.    ' ,   
  dynaset  snapshot.  table      
,     dynaset -   . 
      dynaset,    Microsoft Jet  
 '      .     
 snapshot, <  Jet   .    
    (,   , 
 ),       . 


     3.      	53 

       ,  snapshot^  .  
  dynaset,   ,     
  .       
Microsoft Jet   :      ,   
,     7~~~"""~"""'~""""~ 
           ,  
  forward-only. 

    3.2.3.     

               
,       Data.    
        . 
             
      : 

    txtEmpID.Text  =   recEmployees("EmployeelD") '       
    txtEmpID.Text  =  recEmployees![EmployeelD] 

              
Fields.    ,       
 : 

    '                   
    Print recEmployees.Fields (0) 
    '                 
    For Each fldCurrent In recEmployees.Fields 
    PrTntT fldCurrent.Value Next 


      Null 

              
   .   ,   
 , "  isNuirT" 

    If IsNull(recEmployees("Notes")) Then 
    txtNotes.Text = "   " Else 
    txtNotes . Text = recEmpl'oyees ("Notes") End If 


        

            .  
      ,   . 
             Move. 
     MoveFirst  MoveLast       
     . 
     MoveNext  MovePrevious      
    . 
     Move  ^     . 


    54	    

           Move: 

    recEmployees.Move   +5   '      5      
    recEmployees.Move  -6    '          

    3.2.4.   

     Recordset   ,     
  . 
    ,        
 |    . 

     BOF and EOF 

     BOF  EOF      .   BOF, 
 EOF-True,      . 
       MoveNext  MovePrevious   
 BOF  EOF,   ,      
   BOF  EOF   True    
       .     
  BOF   EOI    (.  . 
2.4).      EOF: 

    recEmployees.MoveNext If  recEmployees.EOF Then 
    recEmployees.MoveLast 
    Beep End   If 


     RecordCount 

     RecordCount    table    
     ,     
  
     RecordCount    dynaset  snapshot  
 ,      .    
 Record-Count  ,     dynaset  
snapshot,       . 
         dynaset  snapshot,  
   MoveLast,    .  
  MoveLa       
   
       RecordCount  ,     
       ,   , 
 \         . 
               
 = : 

    MsgBox   "      -   "   &  _ 
    recEmployees.RecordCount   &   "" 

    :         
  SQL Count. ,  SELECT Count(') FROM 
Employees      Employees. 


     3.      	___                   55 


     AbsolutePosition 

     AbsolutePosition      
    . AbsolutePosition    ( 
,       0).    AbsolutePosition 
  3,    .   
      : 

    IblStatus.Caption  =   "              "   &  _ 
    rs.AbsolutePosition   +   1

     Bookmark

     AbsolutePosition   ,     
   .       
  Bookmark (). 
             
  : 

    Dim varBookmark As  Variant 
    varBookmark  =   recEmployees.Bookmark   '            
    '   [   -       ] 
    recEmployees.Bookmark = varBookmark   '         

    3.2.5.        

               
  . 

        

    1.    Standard EXE. 
    2.    frmCategories. 
    3.     ,     : 

     	|                                                       , 
    	I 
    	I 
    < 	 > 

    . 3.2.   . 

           

    1.        ,    
 : 

    Dim dbCurrent  As   Database 
    Dim  recCategories  As   Recordset 

    2.       Microsoft  3.5 
(  Project | References). 


    56	    


    :     ,    
.olb   ,   (.exe, .dll  .).  
 , ^   (,  
Visual Basic),     .   
        
     Object Browser (. . 1. ). 

    3.     Load     
  
    )     \VB\Nwind.mdb     
     dbCurrent. 
    )   ,  ,    
 Recordset   recCategories. 
    )      . 
    )     CategorylD, CategoryName  Description  
   .      
   :	I 

    Private   Sub  Form_Load() 
    Set  dbCurrent  =  OpenDatabase("C:\VB\Nwind.mdb") 
    Set   recCategories   =  dbCurrent.OpenRecordset("Categories") 
    recCategories.MoveFirst 
    FillFields 
    End  Sub 

    Sub  FillFields() 
    '              '           
   
    txtCategorylD.Text = recCategories.Fields("CategorylD") 
    txtCategoryName.Text = recCategories.Fields("CategoryName") 
    txtDescription.Text  =   recCategories.Fields("Description") 
    End  Sub 

    4.     Unload    : dbCurrent.Close 
    5.      . 

         

      ,     : 
             ; 
             .    
    : 

    Private   Sub   cmdPrevious_Click()    '      "" 
    recCategories.MovePrevious 
    If   recCategories.BOF  Then Beep 
     recCategories.MoveFirst 
    Else 
      FillFields End   
    If End  
    Sub 

    Private   Sub   cmdNext_Click()    '      "" 
    recCategories.MoveNext 


     3.      	57 

    If   recCategories.EOF  Then 
    Beep 
    recCategories.MoveLast Else 
    FillFields 
    End If 
    End Sub 


    3.3.    

            Recordset 
 ,    . 

    3.3.1.   

          Edit,    
      Update: 

    Private   Sub   cmdUpdate_Click   () 
    recEmployees.Edit '  {.    
    recEmployees("LastName")   =   txtLName.Text 
    recEmployees.Update 
    End Sub 

      Update      Edit, 
   7 

     EditMode 

     ,    Edit  AddNew,  
  EditMode.       
 Save (),   Update    
 Add    Edit,   Update,  
   . 
        ,    
  : 

    ________________________________________ 

dbEditNone____
   ._________________ 

dbEditlnProgress 
   Edit       .

dbEditAdd	
   AddNew,         
,        . 

             ,         
      [ EditMode, ,   ,   Edit: 

    Private  Sub  cmdUpdate_Click() 
    If  recEmployees.EditMode  =  dbEditNone   Then 
      recEmployees.Edit 
    End  If 
    recEmployees("LastName") =  txtLastName.Text 
    recEmployees("FirstName") = txtFirstName.Text recEmployees.Update 
    End  Sub 


    58	   

    3.3.2.   

            AddNew.  
 ^     ,      Update. 
           " ",  
*     AddNew. 

    Sub cmdAdd_Click () 
    ClearFields 
    recEmployees.AddNew End Sub 
    Sub ClearFields () '    txtNamel.Text = "" 
    End Sub 

    Sub  cmdUpdate_Click()  '    "" 
    recEmployees("LastName") = txtLName.Text 
    recEmployees.Update 
    End  Sub 

             
"". ;           
    i  . 

      

     CancelUpdate     AddNew  Edit, 
       . 
            
 ,

    Sub cmdCancel_Click () 
    recEmployees.CancelUpdate 
    txtLastName.Text = recEmployees("LastName") 
    txtFirstName.Text = recEmployees("FirstName") End Sub 


    3.3.3.   

            Delete. ! 
 ,         
.          
 . 
           
    .     , 
   MoveNext.        
,      : 

    Private  Sub  cmdDelete_Click() 
    recEmployees.Delete 
    recEmployees.MoveNext 
    If   recEmployees.EOF  Then	
      recEmployees'. Move Last 
    End If 
    FillFields '   
    End Sub 


     3.      	59 

     , _    ,    
RecordCo-unt.       RecordCount 
 . 

    3.4.       Data 

        ""     Data. 
         
    . 
     Recordset   Data   Recordset. 
     Recordset   Data    
  Recordset,   Open Recordset,    
 : 

    Dim  recEmployees   As   Recordset 
    Dim  dbDbl   As   Database 
    Set   recEmployees   =  dbDbl.OpenRecordset   ("Employees") 
    Set   datEmployees.Recordset   =   recEmployees 

     ,   DataField   
      Recordset. 

    3.5.   

     ,       Find   Seek 
     . 

    3.5.1.      dynaset  snapshot 

        dynaset  snapshot     
  FindFirst, FindLast, FindNext  FindPrevious. 
           SQL 
WHERE    WHERE. 
        ,     : 

    recEmployees.FindFirst   "[EmployeeelD]    =   5" 

       FindFirst  FindLast     , 
   , ,     
  .         
Find     ,      ,  
  Bookmark. 
            ,  
    ,     : 

    Private Sub cmdFindFirst_Click() 
    Dim varBookmark as Variant 
    varBookmark = recEmployees.BookMark   '    
    recEmployees.FindFirst "[EmployeelD] = 5" 
    If recEmployees.NoMatch Then 
    recEmployees.BookMark = varBookmark '  
    '    
    End If 
    FillFields '     End Sub 


    60   

       NoMatch,  ,   
 FindFirs . 
            , 
 ( "",    (*). 

    recEmployees.FindFirst   "[LastName]  .Like   'A*'" 

         FindFirst, FindLast, 
FindNext        dynaset  snapshot 
   SQL WHERE. 
             : 

    strSQL = "SELECT * FROM Employees " &     
             "WHERE [LastName] = " & _ 
             "'" & 
             txtLastName.text & 
             "'" 
    Set recEmployees = dbDbl.OpenRecordset(strSQL, dbOpenDynaset) 

          Find   
  ,     SQL   WHERE. 
^   ,  Find   ,  
  " ,    Find    
    . 
    ,     ,    
10 ,  ,       
WHERE,     , , 20000 . 

    3.5.2.     table 

       ^ THnaJa^Jg,.  Seek.  
         Seek . 
          ,   
   Seek: 

     	 

    _||	       I 
    ">"	    
    ">="	      
    "<="	      
    "<"	    

         . ,  
  Name,    LastName  FirstName,    
  Seek  : 

    rs.Index = "Name" 
    rs.Seek "^"/ "", "" 

     Seek      ,   
  Find   dynaset  snapshot.   
Seek       . " --.-.--_ 


     3.      	61 


    3.5.3.      

            
    Categories  ,    
   .        
 "". 
    1.   InputBox,    ,  
    . 
    2.  ,   InputBox,   SQL,  
     Categories,    : 
    "SELECT   *   FROM  Categories   WHERE   [Description]   LIKE   '*_*'" 
    3.   ,  _ 3anpoce_SQL,   
  recCategories.    ""  "" 
    . 
    4.     (recCategories.RecordCount = 0),   
   .         
 . 
       ""    : 

    Private  Sub  cmdFind_Click() Dim  strSQL  As   String Dim  strAnswer  As  
 String 
    strAnswer  =   InputBox("       ",    "  
") '        SQL strSQL   =   "SELECT   *   FROM  
Categories   WHERE    [Description]    LIKE   "   &  _ 
    "'*"   &   strAnswer   &   "*'" 
    Set recCategories = dbCurrent.OpenRecordset(strSQL) If 
recCategories.RecordCount = 0 Then '    
    MsgBox "   .   " 
    Set recCategories = dbCurrent.OpenRecordset("Categories") Else      ' 

,   ,   

    recCategories.MoveFirst 
    FillFields	'    End If End Sub 

    3.6.     SQL 

             
SQL        . 

    3.6.1.    

         (SELECT) ,   
    OpenRecordset  Database.    
   ,      SELECT Products'!: 

    Set  recProducts  =  dbDbl.OpenRecordset("Productsl") 

            
OpenRecordset  QueryTJef^        
  QueryDef,     SELECT: 

    Dim qryProducts As QueryDef 
    Set qryProducts = dbDbl.QueryDefs("Productsl") 
    Set recProducts = qryProducts.OpenRecordset 


    62	    S 


       

        ,     
|  Parameters  QueryDef: 

    Set   qryProducts.Parameters("  ")   = _ CDate (txtBeginDate.text) 


       

                
 .   CreateQueryDef  Database: 

    Set   qryNewQuery  =  dbDbl.CreateQueryDef  _ ("Queryl",    "SELECT   *   
FROM  Employees") 

     Queryl    . 

    3.6.2.   

        SQL,  ,   
    . .   - . 
          Execute  Database. 
              
  . 

    dbDbl.Execute   "_",   dbFailOnError Msgbox   "    
    "   &  _ 
    dbDbl.RecordsAffected  & _ 
    "   " 

     _    . 
     dbFailOnError   Execute   , 
           
   
     RecordsAffected   ,   
,    . 
            QueryDef. 
   ,      Parameters 
 QueryDe     : 

    Dim  qryUpdate  As   QueryDef 
    Set   qryUpdate   =  db.QueryDefs("Updatel") 
    qryUpdate.Parameters    ("    ")   =   .10 
    qryUpdate.Execute   dbFailOnerror 
    Msgbox  qryUpdate.RecordsAffected 

    3.6.3.   SQL 

       (SQL)      
  ,           
. SQ   ,       . 
       SQL    ,    
  -    ,  "Too few 
parameters. Expected (  .  2)".   
 ,    SQL     
      . 

     3.      	63 


     SELECT 

     SQL SELECT       
.  SELECT: 

    SELECT _ FROM _ WHERE  ORDER BY _ 

         Employees   LastName () 
 EmployeelD ( )   ,  EmployeelD   5. 
      EmployeelD: 

    SELECT [LastName], [EmployeelD] FROM Employees WHERE [EmployeelD] > 5 
ORDER BY [EmployeelD] DESC 


     WHERE 

     WHERE     .   
(#)    .   ,   
 SQL,       (, 10  1997 
   5/10/97). 
         SQL: 

    '   WHERE 
    strSQL = "SELECT * FROM Employees WHERE [LastName] = " & "'" & 
txtLName.text & "'" 
    '  WHERE IN 
    StrSQL = "SELECT Employees.[LastName] FROM Employees " & "WHERE 
Employees.Sity IN (','')" 
    '  WHERE BETWEEN 
    strSQL = "SELECT [OrderID] FROM Orders WHERE " & _ 
    " ( [OrderDate] BETWEEN #01/01/96# AND #12/31/96#)" 
    StrSQL = "SELECT [OrderlD] FROM Orders WHERE " & _ 
    "([OrderDate] BETWEEN #" & CDate(txtStartDate.TEXT) & _ "# AND #" & 
CDate(txtEndDate.TEXT) & "#)" 


     ORDER BY 

     ORDER BY       
 .  ASC   , a DESC  
 . 
         Employees   ;  
    LastName (): 

    SELECT   *   FROM  Employees   ORDER  BY    [LastName]    DESC 


      SELECT    

             
 JOIN. ,        
      ,     
 Categories  Products. 


    64     SQL 

     INNER JOIN , , ,   
,     (CategorylD)   Categories 
     Products. 
           Categories   Products: 

    strSQL  =   "SELECT  Categories.[CategoryName],    "   &   _ 
"Products.[ProductName]   "   &  _ "FROM  Categories   "   &  _ "INNER..JOIN   
Products   ON   "   & "Products.[CategorylD]   =   Categories.[CategorylD]" 

            : 

     Categories 
    CategorylD    CategoryName 
       
    \ 
     Products 
    ProduetID    ProductName    CategorylO 
    1	 (.)	1 
    2	 .	7 
    3	 	1 
    / 
    Inner Join 
    CategoryName      ProductName 
    	 (.) 
    	  
    	 . 

    . 3.3.     . 


    3.6.4.   SQL   Visual Basic 

             SQL  
    Visual Basic. 

    :      , 
   SQL   . 

      SELECT 

           SQL  
  OpenRecordset    ,   
 SQL. : 

    Dim stSQL As String 
    strSQL - "SELECT * From Employees" 
    Set recEmployees = dbDbl.OpenRecordset (strSQL) 


      UPDATE 

     SQL UPDATE   .  dbFailOnError 
  ,     
   ,     . 
          SQL UPDATE: 

    strSQL = "UPDATE Products SET [Discount] = 1 " & 
    "WHERE [Discount] = 0" dbDbl.Execute strSQL, dbFailOnError 


     3.       65 


      INSERT 

       INSERT    .   
       Employees: 

    strSQL  =   "INSERT   INTO  Employees   "   &  _ 
    "([First  Name],    [Last  Name])    "   &   _ 
    "VALUES    ('',    '')" dbDbl.Execute   strSQL,   dbFailOnError 


    3.6.5.    SQL 

            Nwind.mdb    
     . 
    1.   . 
    2.   Ten Most Expensive Products    Nwind.mdb 
    .     
Form_Load      ,    , 
        DBGrid,    
 : 

    ii                   ! IB I 
    
     enM ostE xpensiveProducts	UnitPricel 
    >	Cole de Blaye	263.5 123.79' 97 
    Thuringer Rostbratwurst Mishi Kobe Niku 
    
    Sir Rodney's Marmalade	81 
    Carnarvon Tigers	62. 5 1 
    Raclette Courdavault	55: 
    Manjimup Dried Apples	53, 
    Tarte au sucre	49 3 
    Ipoh Coffee	46 
    Rbssle Sauerkraut	456 
    
    :.-,....  !   .1 

    . 3.4.     . 


     :  ( SQL)   Ten Most 
Expensive Products: 

    SELECT   DISTINCTROW  TOP   10/Products . ProductName  AS	.      / 
TenMostExpe'h'siveProducts,   Products .UnitPricej                  "^ FROM 
 Products ORDER  BY   Products.UnitPrice   DESC; 
    fl-' ^-UHi. 

       Form_Load()    : 

    Private   Sub   Form_Load() 
    Dim dbCurrent As Database Dim recProducts As Recordset 
    Set dbCurrent = DBEngine.Workspaces(0).OpenDatabase("C:\VB\Nwind.mdb") Set 
recProducts = dbCurrent.OpenRecordset("Ten Most Expensive _ Products") Set 
datProducts.Recordset = recProducts 
    End Sub 

    3 . 136 


    66     SQ1 

       (    ): 

    Private   Sub   Form_Load() 
    Dim dbCurrent As Database 'Dim recProducts As Recordset 
    Set dbCurrent = DBEngine.Workspaces(0).OpenDatabase("C:\VB\Nwind.mdi" 'Set 
recProducts = dbCurrent.OpenRecordset("Ten Most Expensive _ Products") 
    Set datProducts.Recordset = dbCurrent.OpenRecordset("Ten Most _ Expensive 
Products") 'Set datProducts.Recordset = recProducts 
    End Sub 


    :        Data 
( Visible ~ False)    DataSource  
 DBGrid    Data.     
Recordset   Data   ,   
   . 

      

    1.   Project  Project Properties. 
    2.  Startup Object ( )   . 
    3.  . 
           ,   . 3.4. 

    3.6.6.     

              
Nwind.mdb   . 
    1.   ,         
         Nwind.mdb 
  Employee Sales by Country,     : 
    ii.       
    
      11/1/95 
         j 12/31/35 
    |   
    Country    LastName    [FirstName      ShippedDate    QrderlD 

    . 3.5.     . 


     3.      	67 

         Beginning Date  Ending Date. 

     :  SQL   Employee Sales by Country: 

    PARAMETERS   [Beginning   Date]   DateTime,    [Ending  Date]   DateTirae; 
    SELECT   DISTINCTROW  Employees.Country,   Employees.LastName, 
    Employees.FirstName,   Orders.ShippedDate, 
    Orders.OrderlD,    [Order   Subtotals].Subtotal  AS   SaleAmount 
    FROM  Employees   INNER  JOIN    (Orders   INNER   JOIN    [Order 
    Subtotals]   ON  Orders.OrderlD  =   [Order 
    Subtotals].OrderlD)   ON  Employees.EmployeelD  =  Orders.EmployeelD 
    WHERE   (((Orders.ShippedDate)   Between   [Beginning   Date]   And   [Ending 
    
    Date]) ) ; 

    2.   " "   : 

    Private Sub cmdExecute_Click () 
    Dim strSQL As String 
    Dim dbCurrent As Database 
    Dim recSales As Recordset 
    Dim qrySales As QueryDef 
    Set dbCurrent'= DBEngine.Workspaces(0).OpenDatabase _ ("C:\VB\Nwind.mdb") 
    Set qrySales = dbCurrent.QueryDefs("Employee Sales by Country") 
    qrySales.Parameters("Beginning Date") = CDate(txtBegin) 
    qrySales.Parameters("Ending Date") = CDate(txtEnd) 
    Set recSales = qrySales.OpenRecordset() 
    Set datSales.Recordset = recSales End Sub"" 


