Writing data to a table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been creating queries to append/update data to tables in access. I
was wondering if I could see a sample of code that could update a table
without running a query. Open a table and append data, or open a table with
criteria, and then update. I think I have seen a rs.update routine
somewhere.

Thank you very much for any help or direction!

Janis in MinneSNOWta :)

Merry CHRISTmas!
 
This example (aircode) is for the Customers table in Northwind.

It opens a recordset, using criteria to find a particular company.
If not found, it creates the entry.
If found, it changes the address.

Dim rs As DAO.Recordset
Dim strSql As String
strSql = "SELECT Customers.* FROM Customers WHERE Customers.CompanyName
= ""Consolidated Holdings"";"
Set rs = dbEngine(0)(0).OpenRecordset(strSql)
If rs.EOF Then
rs.AddNew
rs!CustomerID = "CONSO"
rs!CompanyName = "Consolidated Holdings"
rs!Address = "Inseine Boulevade"
rs!City = "Paris"
rs.Update
Else
rs.Edit
rs!Address = "Inseine Boulevade"
rs!City = "Paris"
rs.Update
End If
rs.Close
Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:D[email protected]...
 
Thank you VERY much!!! :)

Janis

Allen Browne said:
This example (aircode) is for the Customers table in Northwind.

It opens a recordset, using criteria to find a particular company.
If not found, it creates the entry.
If found, it changes the address.

Dim rs As DAO.Recordset
Dim strSql As String
strSql = "SELECT Customers.* FROM Customers WHERE Customers.CompanyName
= ""Consolidated Holdings"";"
Set rs = dbEngine(0)(0).OpenRecordset(strSql)
If rs.EOF Then
rs.AddNew
rs!CustomerID = "CONSO"
rs!CompanyName = "Consolidated Holdings"
rs!Address = "Inseine Boulevade"
rs!City = "Paris"
rs.Update
Else
rs.Edit
rs!Address = "Inseine Boulevade"
rs!City = "Paris"
rs.Update
End If
rs.Close
Set rs = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
 
Back
Top