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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a Recordset Collection

Status
Not open for further replies.

thirty4d

MIS
Feb 1, 2001
61
US
I am testing my database using the sample code from Northwind database and I'm trying to apply this to my application.

Rather than hard-coding references to specific "Title" and value, I want to be able to use the code with other text boxes I have in my form?


Private Sub cmdUpdate_Click()

'This example code illustrates a standard use of the Update method
'after using the Edit method and making some changes to a record,
'in a looping structure that iterates through an entire recordset:

Dim dbs As Database
Dim strDBName As String
Dim rst As Recordset

strDBName = "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb"
Set dbs = OpenDatabase(strDBName)
Set rst = dbs.OpenRecordset("Employees", dbOpenTable)
With rst
.MoveFirst
Do While Not .EOF
.Edit
If !Title = "Sales Representative" Then !Title = "Sales Rep"
.Update
.MoveNext
Loop
.Close
End With
dbs.Close

End Sub

Thanks
 
So this code from the Northwind database corrects user's errors if they put the full term Sales Representative in... it changes the record's value to Sales Rep? What exactly are your goals with this database? I'm not the best programmer, but I might be able to help. And afterall, if you are more specific maybe some genius programmer wlil write the code for you.. heh, it's happened to me before.

-Josh -Happen609
Wasting more of your valuable time...
 
Howdy

Create a function which accepts parameters for your update.

Public Sub SQL_UpDate(table as string, column as string, value as variant, frmObject as string)

Your form code can pass all of these variable values to the update function. It should provide you with the flexibility you are seeking.

If you have not written code like this before, I highly recommend you do some reading first.

Cheers
 
demoman and happen609:

Thank you both for the feedback!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top