Loop through table field

L

Luis

Hello,
I have a table with record values that looks like the following:
"ABCD=1234"
I have another table for output where ABCD is a field name. What i'd like to
do is to loop through the field names of the output table and when the field
name is ABCD i want to put 1234 on the record value.

My question is how do i loop through the field names?
 
S

Steven M. Britton

Luis,

This is what I use:

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblABCD")

Dim strABCD, as String

rs.MoveFirst
Do While Not rs.EOF
strABCD= rs!FieldABCD

If strABCD = "ABCD" Then
rs.edit
rs!FieldABCD = strABCD & "1234"
rs.Update
rs.MoveNext
End If

Loop
 
J

John Vinson

Hello,
I have a table with record values that looks like the following:
"ABCD=1234"
I have another table for output where ABCD is a field name. What i'd like to
do is to loop through the field names of the output table and when the field
name is ABCD i want to put 1234 on the record value.

My question is how do i loop through the field names?

No loop is actually needed: you can use the fieldname itself as an
index to the recordset's Fields collection. Assuming you have this
"ABCD=1234" value in the variable strIn,

Dim rs As DAO.Recordset
Dim strField As String
Dim strValue As String
Set rs = db.OpenRecordset("outputtable", dbOpenDynaset)
<navigate to the desired record and use rs.Edit, or use rs.AddNew to
open a new record, as appropriate>
strField = Left(strIn, InStr(strIn, "=") - 1)
strValue = Mid(strIn, InStr(strIn, "=") + 1)
rs.Fields(strField) = strValue
rs.Update


John W. Vinson[MVP]
 

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