Update a field in a table

D

Duane

Hello,

I am trying to update a field in my table. I want to concatenate the data
that is in the field, i.e. L-K with an incementing numbering system.

When the code is run the field ends up looking like the following:
L-K1
L-K2
L-K3
etc.

Ideally, I would like the update to look like this:
L-K01
L-K02
L-K03
L-K04
....
L-K10
L-K11
etc.

Here is my code.

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

Dim x As Integer
Dim strEtching As String

rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.LockType = adLockOptimistic

rst.Open "SELECT * FROM tblTool"

x = 1
Do Until rst.EOF
strEtching = rst("Etching")
rst("Etching") = strEtching & x
rst.Update
x = x + 1
rst.MoveNext
Loop

rst.Close

Thanks in advance
 
D

Douglas J. Steele

Are you saying that all the rows in the recordset initially have L-K in
field Etching?

rst("Etching") = strEtching & Format(x, "00")
 
S

Stan

Try a variation of this as your variable is a string and not an integer.
Private Sub cmdTest_Click()
Dim strTest As String
Dim x As Integer
x = 1
Do Until x = 15 'loop for test purposes
strTest = "K"
'The potential solution
If x < 10 Then
strTest = strTest & "0" & x
Else
strTest = strTest & x
End If

x = x + 1
Debug.Print strTest
Loop

End Sub

results
K01
K02
K03
K04
K05
K06
K07
K08
K09
K10
K11
K12
K13
K14
 
D

Duane

Thank you both for your responses.

Douglas J. Steele said:
Are you saying that all the rows in the recordset initially have L-K in
field Etching?

rst("Etching") = strEtching & Format(x, "00")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top