Updating table using Recordset

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

Guest

hi,
i have a table named Board with the field names; SerialNumber,
Description,Status,Department,Qty and I want to update it using a recordset
with the data in my form.
help me pls.

resti
 
Add a button to your form with the following OnClick Event

Set dbs = OpenDatabase("c:\databasepath\databasename.mdb")
QryAdd = "Board"
Set RstAdd = dbs.OpenRecordset(QryAdd, dbOpenDynaset)

With RstAdd
.AddNew

(Assuming your data that you want to add to the table is entered into text
boxes)

!SerialNumber = TbxSerialNumber.Value
!Description = TbxDescription.Value
!Department= TbxDepartment.Value
!Qty = TbxQty.Value
.Update
RstAdd.Close
End With

You have to remember that:
1) With this method you can enter duplicate data unless a field is set to
Indexed no duplicates
2) You have to "blank" the form after this event otherwise a user can keep
 
Further to what Helgard posted, 2 other solutions and perhaps a bit quicker
would be to run a paramaterized query or use inline sql:

In-line sql example:

Dim sql as String

sql = "INSERT INTO Board (SerialNumber, Description, Department, Qty) VALUES
('" & txtSerialNumber.Value & "','" & txtDescription.Value & "','" &
txtDepartment.Value & "'," & Cstr(txtQty.Value) & ")"

CurrentDB.Execute(sql)
 
Back
Top