Maybe you can adapt this to your needs. This is DAO code. If you don't
already have it, you'll need to add a reference (Tools, References in the
VBA editor) to the Microsoft DAO 3.6 Object Library. Alternatively, if you
are more familiar with ADO, it should not be difficult to adapt this code to
use ADO instead. This code assumes that the recordset will not contain more
fields than there are controls on the report. It could be made more robust
by adding a check for that.
Private Sub Report_Open(Cancel As Integer)
Dim lngLoop As Long
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset(Me.RecordSource)
For lngLoop = 0 To rst.Fields.Count - 1
Me.Controls("Label" & lngLoop + 1).Caption =
rst.Fields(lngLoop).Name
Me.Controls("Textbox" & lngLoop + 1).ControlSource =
rst.Fields(lngLoop).Name
Next lngLoop
End Sub
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.