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

Editing records in a table 1

Status
Not open for further replies.

Dohhh

MIS
Mar 27, 2002
3
0
0
US
I am having trouble editing records using a form. When I open the form, I get a complile error for rec.Edit. Here is the code:

Private Sub Command0_enter()

Dim dbs As Database
Dim rec As Recordset
Dim strTable As String

Dim intLength As Integer

Dim strNewID As String

strTable = "Active Employees List"

Set dbs = CurrentDb()
Set rec = dbs.OpenRecordset(strTable, dbOpenTable)

rec.MoveFirst

Do
rec.Edit

rec![Employee Number] = Right$("0000" & rec![Employee Number], 4)

rec.Update

rec.MoveNext

Loop While Not rec.EOF

rec.Close

End Sub

Some of the records in the table are transferred without the leading 0, so I am attempting to add that 0 back in so all of the numbers have 4 didgits. This code has worked before, but for some reason will not run now. Any ideas? Thanks.
 
You could do all this with an update statement
[blue][tt]
Dim strSQL = "UPDATE [Active Employees List] " & _
"SET [Employee Number] = " & _
" Right$("0000" & [Employee Number]), 4) "
dbs.Execute strSQL
[/tt][/blue]
For your current problem, be explicit about
[blue][tt]
Dim dbs As DAO.Database
Dim rec As DAO.Recordset
[/tt][/blue]
and you have checked a reference to DAO 3.x.

If you have the ADO libraries referenced then it may be making "rst" an ADO rather than a DAO recordset.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top