How in access 2000 to add a new record or several records to a table using a query?

    1 answer 1

    One of the convenient ways to do this.
    Create a request. You write something like this in it:

    INSERT INTO таблица ( Фамилия, Имя, Отчество, Серия_паспорта, Номер_паспорта) VALUES (фамилия_, имя_, отчество_, серия_паспорта_, номер_паспорта_); 

    Here in the VALUES (...) expression the parameters that need to be filled in when invoking the query.
    Save the request. We give it a name, for example, ЗапросНаДобавление .
    Open Visual Basic and write the command:

     Dim q As dao.QueryDef Set q = CurrentDb.QueryDefs("ЗапросНаДобавление") 'имя хранимого запроса 'устанавливаем входящие параметры из полей для ввода на форме q.Parameters("фамилия_").Value = StrConv(ПолеФамилия.Value, vbUpperCase) q.Parameters("имя_").Value = StrConv(ПолеИмя.Value, vbUpperCase) q.Parameters("отчество_").Value = StrConv(ПолеОтчество.Value, vbUpperCase) q.Parameters("серия_паспорта_").Value = StrConv(ПолеСерия.Value, vbUpperCase) q.Parameters("номер_паспорта_").Value = ПолеНомер.Value 'выполняем запрос \\ не действует для SELECT q.Execute 'Обязательно закрываем q.Close: Set q = Nothing 

    As you already understood, the data for filling is taken from the fields to be entered on the Access form, for example, when you click on the " Save " button. And if you need to add several records, it’s just a loop (call the code above several times). Only for more speed, you need to close the connection after performing a series of add requests.