Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing Records using a form!!!

Status
Not open for further replies.

Danielle17

Technical User
Apr 17, 2001
102
US
I have created a form that contains a combo box that pulls up certain records. I'd like it so that the user could edit the information and then click the command button and the info would be changed in the table. I have it working so that if the info is changed on the form it will also change in the table. I also have two subforms that I would like to be able to edit. I couldn't figure out how to build the event for that...I'm not extremely good at coding. The problem with the code I have now is that when I do make a change on the form and then click the command button the change will take place but then when I go to check the changes in the table I noticed that it changes the record it's supposed to but it also changes the first record in the the table. I'm not sure why it's doing this. Here's the code for the command button...Any help would be appreciated:)

Private Sub cmdEditJob_Click()
Dim db As Database
Dim tdEdit As TableDef
Dim rsEdit As Recordset
Dim fmEdit As Form_Editing

Set db = CurrentDb
Set tdEdit = db.TableDefs("zJobTable")
Set rsEdit = tdEdit.OpenRecordset()

rsEdit.edit

rsEdit.Fields("Customer") = txtCustomer
rsEdit.Fields("Phone #") = txtPhNum
rsEdit.Fields("Contact") = txtContact
rsEdit.Fields("PO#") = txtPO
rsEdit.Fields("Start Date") = txtStDt
rsEdit.Fields("End Date") = txtEnDt
rsEdit.Fields("Notes") = txtNotes
rsEdit.Fields("Description") = txtDescr

rsEdit.Update

End Sub

p.s. I don't have the code for the subforms on there yet. I'm not exactly sure how to do it. Any suggestions?
 
Hi Danielle17!

I've worked with DAO quite a bit and from what I can tell from your coding that it's pretty generic... I use DAO to modify large amounts of data at a particular time for a specific reason - it's much faster than a query... I'm not sure if this will help you, but I thought I would write some quick code to let you know how I do it... Take what you want and throw what you don't want away... :)

Dim dbs as Database, rst as Recordset
Dim Ctr,Ttl as Long ' Use Integer if less than 32,000+

Set dbs as CurrentDb
Set rst as dbs.openrecordset("RecordTable",dbopendynaset)
Ctr = 0
Ttl = 0
docmd.OpenForm "StatusBox" ' Simple form that displays a label box to change

rst.MoveLast
rst.MoveFirst ' Populates recordset
rst.FindFirst "[ID] = " & Me!ID
Do While Not rst.NoMatch
Ttl = Ttl + 1
rst.FindNext "[ID] = " & Me!ID
Loop

rst.MoveFirst
rst.FindFirst "[ID] = " & Me!ID
Do While Not rst.NoMatch
Ctr = Ctr + 1
Forms!StatusBox!Status.Caption = "Changing record " & Ctr & " of " & Ttl
rst.Edit
rst!Age = Me!Age
rst.Update
rst.FindNext "[ID] = " & Me!ID
Loop

rst.Close
DoCmd.Close Forms,"StatusBox"


Like I said, this seems to work pretty good for me and guarantees changes to only that which you want changed...

Roy (aka BanditLV)
Las Vegas, NV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top