Help with code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

For every record in a recordset I would like to update a textfield1 with the
value of a numberfield and then add the letter "a.jpg" in the end of in the
end.
And the textfield2 with the value of the numberfield + "b.jpg" and the
textfield3 with the value of the numberfield + "c.jpg" etc.

Example below:

Numberfield Textfield1 Textfield2
Textfield3
1 1a.jpg 1b.jpg
1c.jpg
23 23a.jpg 23b.jpg
23c.jpg

All the above fileds are in the same table.

I do not know how to do this if use recordset and loop throw with code or
make an updatequery....and which syntax to use.

Thank you in advance

Mattias
 
Mattias

If it were me, I would use an update query rather than iterate through a
recordset. Code might look like:

(UNTESTED)
Private Sub UpDateStuff()
Dim strSql as String
strSql = "UPDATE tblYourTable " _
& "SET tblYourTable.TextField1 = [NumberField] & 'a.jpg', " _
& "tblYourTable.TextField2 = [NumberField] & 'b.jpg', " _
& "tblYourTable.TextField3 = [NumberField] & 'c.jpg' " _
& "WHERE (whatever conditions you need to apply)"
DoCmd.SetWarnings False
DoCmd.RunSql strSql
DoCmd.SetWarnings True
End Sub

Hope this helps

Ron W
 
Thank you Ron!

works nicely.

Mattias

Ron Weiner said:
Mattias

If it were me, I would use an update query rather than iterate through a
recordset. Code might look like:

(UNTESTED)
Private Sub UpDateStuff()
Dim strSql as String
strSql = "UPDATE tblYourTable " _
& "SET tblYourTable.TextField1 = [NumberField] & 'a.jpg', " _
& "tblYourTable.TextField2 = [NumberField] & 'b.jpg', " _
& "tblYourTable.TextField3 = [NumberField] & 'c.jpg' " _
& "WHERE (whatever conditions you need to apply)"
DoCmd.SetWarnings False
DoCmd.RunSql strSql
DoCmd.SetWarnings True
End Sub

Hope this helps

Ron W
Mattias said:
Hi

For every record in a recordset I would like to update a textfield1 with the
value of a numberfield and then add the letter "a.jpg" in the end of in the
end.
And the textfield2 with the value of the numberfield + "b.jpg" and the
textfield3 with the value of the numberfield + "c.jpg" etc.

Example below:

Numberfield Textfield1 Textfield2
Textfield3
1 1a.jpg 1b.jpg
1c.jpg
23 23a.jpg 23b.jpg
23c.jpg

All the above fileds are in the same table.

I do not know how to do this if use recordset and loop throw with code or
make an updatequery....and which syntax to use.

Thank you in advance

Mattias
 
Back
Top