I know this has to be a pretty basic function, and I have a goofy error somewhere that I am hoping someone here can point out. I am simply trying to loop through a recordset and display the values contained in a field "TAG". Code is
It seems to loop through my table, and give me the right amount of records (i.e., 5), but each record has the same value, the first one. So the table looks like this
Tag
X4-2A
X4-2B
X4-2C
X4-2D
X4-2E
I get a report that shows a column title "TAG" and then five values below that, each of which is "X4-2A". Any ideas what I have coded incorrectly to not get the correct values?
Thanks much
Code:
Private Sub Print_Report_Click() Dim db As DAO.Database Dim rpt As Report Dim rst As DAO.Recordset Dim fld As DAO.Field Dim sSQL As String Dim txtbx As Access.TextBox Dim lblnew As Access.Label Dim lngleft As Long Dim lngtop As Long sSQL = "SELECT TAG FROM ESGBKR" Set db = CurrentDb Set rst = db.OpenRecordset(sSQL, dbOpenDynaset) Set rpt = CreateReport rpt.RecordSource = sSQL 'Set columns Set lblnew = CreateReportControl(rpt.Name, acLabel, acDetail, , "TAG") lngtop = lngtop + 200 If Not (rst.EOF And rst.BOF) Then rst.MoveFirst Do Until rst.EOF = True For Each fld In rst.Fields Set txtbx = CreateReportControl(rpt.Name, acTextBox, acDetail, fld.name, lngleft, lngtop) txtbx.SizeToFit lngtop = lngtop + 25 + txtbx.Height Next fld rst.MoveNext Loop Else MsgBox "No Records Available" End If DoCmd.OpenReport rpt.Name, acViewPreview rst.Close Set rst = Nothing Set db = Nothing Set rpt = Nothing End Sub
Tag
X4-2A
X4-2B
X4-2C
X4-2D
X4-2E
I get a report that shows a column title "TAG" and then five values below that, each of which is "X4-2A". Any ideas what I have coded incorrectly to not get the correct values?
Thanks much
Comment